/meteor-universe-autoform-select

Meteor universe autoform select

Primary LanguageJavaScript

Universe autoform select

An add-on Meteor package for aldeed:autoform. Provides a single custom input type, "universe-select".

This package is part of Universe, a framework based on Meteor platform maintained by Vazco.

It works standalone, but you can get max out of it when using the whole system.

Demo

http://universe-autoform-select-demo.meteor.com

https://github.com/vazco/meteor-universe-autoform-select-demo.git

Prerequisites

The plugin library must be installed separately.

In a Meteor app directory, enter:

$ meteor add aldeed:autoform

Installation

In a Meteor app directory, enter:

$ meteor add vazco:universe-autoform-select

Usage

Specify "universe-select" for the type attribute of any input. This can be done in a number of ways:

In the schema, which will then work with a quickForm or afQuickFields:

{
  tags: {
    type: [String],
    autoform: {
      type: "universe-select",
      afFieldInput: {
        multiple: true
      }
    }
  }
}

Or on the afFieldInput component or any component that passes along attributes to afFieldInput:

{{> afQuickField name="tags" type="universe-select" multiple=true}}

{{> afFormGroup name="tags" type="universe-select" multiple=true}}

{{> afFieldInput name="tags" type="universe-select" multiple=true}}

Autosave

If you enable autosave option in autoform, then it triggering after blur of universe-select (if multiple).

Options

universe-select options
Option Description Type Default
options Required. A function returning either an array of options, or a Mongo.Cursor. The function is re-evaluated automatically using Tracker when its reactive data sources change. function undefined
uniPlaceholder Optional. A placeholder option. String null
disabled Optional. Boolean false
multiple Optional. Boolean false
remove_button Optional. Boolean true
values_limit Optional. Number undefined
create Optional. Allows the user to create a new items that aren't in the list of options. Boolean true
createOnBlur Optional. If true, when user exits the field (clicks outside of input or presses ESC) new option is created and selected (if `create`-option is enabled). Boolean true
createSlug Optional. After creating new label, converts value into a slug. Boolean true
createMethod Optional. Name of method to call after create new item. function (label, value) undefined
optionsMethod Optional. Name of method to get more items. Method should return array of options. function (query) undefined
optionsMethodParams Optional. Additional params for optionsMethod. Object undefined

Example optionsMethod:

Meteor.methods({
    getOptions: function (options) {
        this.unblock();
        var searchText = options.searchText;
        var values = options.values;
        
        if (searchText) {
            return OptionsCollection.find({label: {$regex: searchText}}, {limit: 5}).fetch();
        } else if (values.length) {
            return OptionsCollection.find({value: {$in: values}}).fetch();
        }
        return OptionsCollection.find({}, {limit: 5}).fetch();
    }
});