├── .jshintrc ├── LICENSE ├── README.md ├── package.js ├── universe-autoform-select.html └── universe-autoform-select.js /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "bitwise": true, 3 | "curly": true, 4 | "eqeqeq": true, 5 | "freeze": true, 6 | "immed": true, 7 | "newcap": true, 8 | "noarg": true, 9 | "noempty": true, 10 | "nonbsp": true, 11 | "quotmark": true, 12 | "undef": true, 13 | "unused": true, 14 | "strict": true, 15 | "trailing": true, 16 | "maxcomplexity": 12, 17 | "maxlen": 120, 18 | "globalstrict": true, 19 | "devel": true, 20 | "node": true, 21 | "browser": true, 22 | "jquery": true, 23 | "esnext": true, 24 | "globals": { 25 | "ReactiveVar": false, 26 | "AutoForm": false, 27 | "Meteor": false, 28 | "Template": false, 29 | "_": false, 30 | "Package": false, 31 | "getSlug": false 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Vazco 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | vazco/Universe Autoform Select 3 |

4 | 5 |   6 | 7 | 8 | 9 |   10 | 11 | An add-on Meteor package for [aldeed:autoform](https://github.com/aldeed/meteor-autoform). Provides a single custom input type, "universe-select". 12 | 13 | > This package is part of Universe, a framework based on [Meteor platform](http://meteor.com) 14 | maintained by [Vazco](http://www.vazco.eu). 15 | 16 | > It works standalone, but you can get max out of it when using the whole system. 17 | 18 | ## Demo 19 | 20 | 21 | http://universe-autoform-select.stg.vazco.eu/ 22 | 23 |
24 | 25 | https://github.com/vazco/meteor-universe-autoform-select-demo.git 26 | 27 | 28 | 29 | ## Prerequisites 30 | 31 | The plugin library must be installed separately. 32 | 33 | In a Meteor app directory, enter: 34 | 35 | ```bash 36 | $ meteor add aldeed:autoform 37 | ``` 38 | 39 | ## Installation 40 | 41 | In a Meteor app directory, enter: 42 | 43 | ```bash 44 | $ meteor add vazco:universe-autoform-select 45 | ``` 46 | 47 | ## For use without autoform 48 | 49 | Universe selectize standalone: 50 | 51 | 52 | https://github.com/vazco/meteor-universe-selectize/ 53 | 54 | 55 | 56 | ## Usage 57 | 58 | Specify "universe-select" for the `type` attribute of any input. This can be done in a number of ways: 59 | 60 | In the schema, which will then work with a `quickForm` or `afQuickFields`: 61 | 62 | ```js 63 | { 64 | tags: { 65 | type: [String], 66 | autoform: { 67 | type: "universe-select", 68 | afFieldInput: { 69 | multiple: true 70 | } 71 | } 72 | } 73 | } 74 | ``` 75 | 76 | Or on the `afFieldInput` component or any component that passes along attributes to `afFieldInput`: 77 | 78 | ```js 79 | {{> afQuickField name="tags" type="universe-select" multiple=true}} 80 | 81 | {{> afFormGroup name="tags" type="universe-select" multiple=true}} 82 | 83 | {{> afFieldInput name="tags" type="universe-select" multiple=true}} 84 | ``` 85 | 86 | ## Autosave 87 | 88 | If you enable autosave option in autoform, then it triggering after blur of universe-select (if multiple). 89 | 90 | ## Options 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 |
universe-select options
OptionDescriptionTypeDefault
optionsRequired. 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.functionundefined
uniPlaceholderOptional. A placeholder option.Stringnull
optionsPlaceholderOptional. Show placeholder in options dropdown.Boolean or Stringfalse
uniDisabledOptional.Booleanfalse
multipleOptional. Booleanfalse
removeButtonOptional. Booleantrue
valuesLimitOptional. Numberundefined
createOptional. Allows the user to create a new items that aren't in the list of options. Booleantrue
createOnBlurOptional. 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). Booleantrue
createSlugOptional. After creating new label, converts value into a slug. Booleantrue
createMethodOptional. Name of method to call after create new item. Method can return new value for item. function (label, value)undefined
optionsMethodOptional. Name of method to get more items. Method should return array of options. Stringundefined
optionsMethodParamsOptional. Additional params for optionsMethod. Objectundefined
183 | 184 | 185 | ## Example optionsMethod: 186 | 187 | ```js 188 | Meteor.methods({ 189 | getOptions: function (options) { 190 | this.unblock(); 191 | var searchText = options.searchText; 192 | var values = options.values; 193 | 194 | if (searchText) { 195 | return OptionsCollection.find({label: {$regex: searchText}}, {limit: 5}).fetch(); 196 | } else if (values.length) { 197 | return OptionsCollection.find({value: {$in: values}}).fetch(); 198 | } 199 | return OptionsCollection.find({}, {limit: 5}).fetch(); 200 | } 201 | }); 202 | ``` 203 | 204 | ## License 205 | 206 | 207 | 208 | **Like every package maintained by [Vazco](https://vazco.eu/), Universe Autoform Select is [MIT licensed](https://github.com/vazco/uniforms/blob/master/LICENSE).** 209 | -------------------------------------------------------------------------------- /package.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | Package.describe({ 4 | name: 'vazco:universe-autoform-select', 5 | summary: 'Custom "afUniverseSelect" input type for AutoForm, with the appearance as selectize', 6 | version: '0.4.1', 7 | git: 'https://github.com/vazco/meteor-universe-autoform-select.git' 8 | }); 9 | 10 | Package.onUse(function (api) { 11 | api.versionsFrom('1.2.1'); 12 | 13 | if (!api.addAssets) { 14 | api.addAssets = function (files, platform) { 15 | api.addFiles(files, platform, {isAsset: true}); 16 | }; 17 | } 18 | 19 | api.use(['ecmascript', 'templating', 'underscore'], 'client'); 20 | api.use('aldeed:autoform@6.0.0'); 21 | api.use('vazco:universe-selectize@0.1.17', 'client'); 22 | 23 | api.addFiles([ 24 | 'universe-autoform-select.html', 25 | 'universe-autoform-select.js' 26 | ], 'client'); 27 | }); 28 | -------------------------------------------------------------------------------- /universe-autoform-select.html: -------------------------------------------------------------------------------- 1 | 22 | -------------------------------------------------------------------------------- /universe-autoform-select.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | AutoForm.addInputType('universe-select', { 4 | template: 'afUniverseSelect', 5 | valueIsArray: true, 6 | valueOut() { 7 | return this.val(); 8 | }, 9 | contextAdjust(context) { 10 | // build items list 11 | 12 | context.items = _.map(context.selectOptions, function (opt) { 13 | return { 14 | label: opt.label, 15 | value: opt.value, 16 | selected: _.contains(context.value, opt.value) 17 | }; 18 | }); 19 | 20 | //autosave option 21 | if (AutoForm && typeof AutoForm.getCurrentDataForForm === 'function') { 22 | context.atts.autosave = AutoForm.getCurrentDataForForm().autosave || false; 23 | context.atts.placeholder = AutoForm.getCurrentDataForForm().placeholder || context.atts.uniPlaceholder || null; 24 | context.atts.uniDisabled = !!AutoForm.getCurrentDataForForm().disabled || context.atts.uniDisabled || false; 25 | } 26 | 27 | context.atts.removeButton = context.atts.removeButton || context.atts.remove_button; // support for previous version 28 | 29 | context.atts.dataSchemaKey = context.atts['data-schema-key']; 30 | 31 | return context; 32 | } 33 | }); 34 | --------------------------------------------------------------------------------