Giter Site home page Giter Site logo

autoform-picker's Introduction

AutoForm Picker

Meteor AutoForm widget which allow to pick (or create new) document from given Mongo Collection.

Motivation

We needed an AutoForm plugin which:

  • would allow to select some value from given collection
  • could work with big amount of data (e.g. 100 000 entries/docs)
  • while filtering/searching, would transliterate search phrase
  • would allow to create new document in DB right from widget

The closest solution at that time was aldeed:autoform-select2, but it's not good when you work with big amount of data (it's not good idea to subscribe for 100 000 docs and find/filter them on client. Also autoform-select2 not support possibility to create new document/enty in DB while filling form.

How does it work? (Features)

  • Creates index of fields we will use to search/filter.
  • Do filter/search on server and then send to client max 20 filtered results.
  • Supports transliteration. E.g. allow search for Rīga by typing riga or Рига.
  • Uses quickForm to create new entry into DB (you can also create own form template with autoForm if you need).

Usage manual

  1. Install package: meteor add nous:autoform-picker (previously known as chompomonim:autoform-picker)

  2. To get possibility to search on server (using some kind of index), you'll need to register your Collection:

// lib/collection.js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { SimpleSchema } from 'meteor/aldeed:simple-schema';
import searchIn from 'meteor/nous:search-in';

/* This is optional. In case you use Colection transformations, we also support them.
export class ClientBase {
   get name() {
       return `${this.first_name} ${this.last_name}`
   }
   ...
}

export const Clients = new Mongo.Collection('clients', {
   transform: function(doc) {
       return _.extend(new ClientBase, doc)
   }
});
*/

export const Clients = new Mongo.Collection('clients');

// Your schema here

if (Meteor.isServer) {
 searchIn.register(Clients, function () {
   return {
     name: `${this.first_name} ${this.last_name}`,
     address: this.address,
     email: ((this.emails != null) ? this.emails : []).join(' ')
   }
 });
}
  1. In your schema you should add toic-picker autoform type.
SomeSchema = new SimpleSchema({
  ...
  client_id: {
    type: String,
    regEx: SimpleSchema.RegEx.Id,
    autoform: {
      type: "toic-picker",
      afFieldInput: {
        collection: 'clients',           // Collection name
        choose: ()=> function () { return this.name }, // What you want to see as a item name/label of select results. Yes, it's function as a parametr for other function.
        class: ()=> ClientBase,          // (optional) Function which returns collection base.
        fields: ["name", "category_ids"] // (optional) If you'll use default template (quickForm), you can select which fielts do you need there.
      }
    }
  }
})
  ...

Example project: https://github.com/chompomonim/autoform-picker-example

autoform-picker's People

Contributors

chompomonim avatar

Stargazers

 avatar Niraj !!! avatar Kris Haamer avatar Ashwin Shankar avatar  avatar Yuom Theara avatar Fabio Dias Rollo avatar Michael Nino Evensen avatar Ricardo do Valle avatar Aaron Adams avatar

Watchers

Ignas Mikalajūnas avatar  avatar Anatoly Ressin avatar Rimvydas Naktinis avatar James Cloos avatar

Forkers

toontoet

autoform-picker's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.