├── .gitignore
├── LICENSE
├── README.md
├── angular-schema-form-dynamic-select.js
├── angular-schema-form-dynamic-select.min.js
├── app.css
├── app.js
├── bower.json
├── gulpfile.js
├── index.html
├── karma.conf.js
├── package.json
├── src
├── angular-schema-form-dynamic-select.js
├── strapmultiselect.html
├── strapselect.html
├── uiselect.html
└── uiselectmultiple.html
├── test
├── testdata.json
├── testdata_mapped.json
└── tests.js
└── ui-sortable.js
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 |
5 | # Runtime data
6 | pids
7 | *.pid
8 | *.seed
9 |
10 | # Directory for instrumented libs generated by jscoverage/JSCover
11 | lib-cov
12 |
13 | # Coverage directory used by tools like istanbul
14 | coverage
15 |
16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
17 | .grunt
18 |
19 | # Compiled binary addons (http://nodejs.org/api/addons.html)
20 | build/Release
21 |
22 | # Dependency directory
23 | # Commenting this out is preferred by some people, see
24 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
25 | bower_components
26 | node_modules
27 |
28 | # Users Environment Variables
29 | .lock-wscript
30 | .DS_Store
31 |
32 |
33 | # IDE configuration files
34 | .idea
35 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 chengz
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 | [](#bower)
2 | [](https://www.npmjs.org/package/angular-schema-form-dynamic-select)
3 | [](https://gitter.im/OptimalBPM/angular-schema-form-dynamic-select?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4 |
5 |
6 | # WARNING: This component is currently looking for maintainers!
7 |
8 | Angular Schema Form Dynamic Select (ASFDS) add-on
9 | =================================================
10 |
11 | This add-on integrates the [angular-strap-select](https://github.com/mgcrea/angular-strap/tree/master/src/select) and the [angular-ui-select](https://github.com/angular-ui/ui-select) components
12 | to provide fully featured drop downs to [angular-schema-form](https://github.com/Textalk/angular-schema-form).
13 |
14 | It is drop-in compliant with angular-schema-forms existing selects, which makes using it a breeze, no adaptations are needed.
15 |
16 | All settings are kept in the form, separating validation and UI-configuration.
17 |
18 | *Note about UI-select:
19 | The ui-select support is quite new and while many things work, it is still somewhat partial, so WRT the features below, they apply to angular-strap-select. For that reason, ui-select has a [special section in the documentation](https://github.com/OptimalBPM/angular-schema-form-dynamic-select#ui-select).*
20 |
21 | # Features:
22 |
23 | * Static and dynamic lists
24 | * Single and multiple select
25 | * Convenient HTTP GET/POST and property mapping functionality
26 | * Filters
27 | * Sync and Async callbacks
28 | * All callbacks referenced either by name (string) or reference
29 | * [Angular schema form options](https://github.com/Textalk/angular-schema-form/blob/development/docs/index.md#standard-options)
30 | * Supported:
31 | * key, type, title, description, placeholder
32 | * enum
33 | * notitle, onChange, condition
34 | * htmlClass, labelHtmlClass and fieldHtmlClass
35 | * validationMessage
36 | * Not supported(will be added):
37 | * readonly, copyValueTo,
38 | * Not applicable(will not be added due to the nature of drop downs, [disagree?](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/issues)):
39 | * feedback
40 |
41 |
42 |
43 | # Example
44 |
45 | There is a live example at [http://demo.optimalbpm.se/angular-schema-form-dynamic-select/](http://demo.optimalbpm.se/angular-schema-form-dynamic-select/).
46 |
47 | The example code is in the repository, it's made up of the index.html, app.js, test/testdata.json and test/testdata_mapped.json files.
48 |
49 | To run it locally, simply clone the repository:
50 |
51 | git clone https://github.com/OptimalBPM/angular-schema-form-dynamic-select.git
52 | cd angular-schema-form-dynamic-select
53 | bower update
54 |
55 | ..and open index.html in a browser or serve using your favorite IDE.
56 |
57 | However, to make the *entire* example work properly, as it contains UI-select components, please install the [ui-select dependencies](https://github.com/OptimalBPM/angular-schema-form-dynamic-select#ui-select) as well.
58 |
59 | (you will need to have [bower installed](http://bower.io/#install-bower), of course)
60 |
61 | # Help
62 |
63 | What are my options if I feel I need help?
64 |
65 | ### I don't understand the documentation
66 | The prerequisite for understanding the ASFDS documentation [below](https://github.com/OptimalBPM/angular-schema-form-dynamic-select#installation-and-usage) is that you have a basic understanding of how to use [Angular Schema Form](https://github.com/Textalk/angular-schema-form#basic-usage).
67 | So if you understand that, and still cannot understand the documentation of ASFDS, it is probably not your fault. [Please create an issue](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/issues) in those cases.
68 |
69 | ### I have a question
70 | If you have a question and cannot find an answer for it in the documentation below, [please create an issue](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/issues).
71 | Questions and their answers have great value for the community.
72 |
73 | ### I have found a bug
74 | [Please create an issue](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/issues).
75 | Be sure to provide ample information, remember that any help won't be better than your explanation.
76 |
77 | Unless something is obviously wrong, you are likely to be asked to provide a [plunkr](http://plnkr.co/)-example, displaying the erroneous behaviour.
78 |
79 | While this might feel troublesome, a tip is to always make a plunkr that have the same external requirements as your project.
80 | It is great for troubleshooting those annoying problems where you don't know if the problem is at your end or the components'.
81 | And you can then easily fork and provide as an example.
82 | You will answers and resolutions way quicker, also, many other open source projects require it.
83 |
84 | ### I have a feature request
85 | [Good stuff! Please create an issue!](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/issues)
86 | (features are more likely to be added the more users they seem to benefit)
87 |
88 | ### I want to discuss ASFDS or reach out to the developers, or other ASFDS users
89 | [The gitter page](https://gitter.im/OptimalBPM/angular-schema-form-dynamic-select) is good for when you want to talk, but perhaps doesn't feel that the discussion has to be indexed for posterity.
90 |
91 |
92 | # Glossary
93 |
94 | * List items: the items that make up the selection list, for example the items in a drop down.
95 | * ASFDS: Angular-Schema-Form-Dynamic-Select
96 |
97 | # Installation and usage
98 |
99 | ASFDS is an add-on to the angular-schema-form. To use it (in production), follow these steps:
100 |
101 | ### Dependencies
102 | Easiest way is to install is with bower, this will also include dependencies:
103 |
104 | ```bash
105 | $ bower install angular-schema-form-dynamic-select
106 | ```
107 |
108 | If you want to use the develop branch:
109 |
110 | ```bash
111 | $ bower install angular-schema-form-dynamic-select#develop
112 | ```
113 |
114 | \#develop is not recommended for production, but perhaps you want to use stuff from the next version in development.
115 |
116 | You can also use npm for installation:
117 |
118 | ```bash
119 | $ npm i angular-schema-form-dynamic-select
120 | ```
121 |
122 | ### HTML
123 | Usage is straightforward, simply include and reference:
124 | ```html
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 | ```
138 | Note: Make sure you load angular-schema-form-dynamic-select.js **after** loading angular schema form.
139 |
140 | ### Configuring your angular module
141 |
142 | When you create your module, be sure to make it depend on mgcrea.ngStrap as well:
143 | ```js
144 | angular.module('yourModule', ['schemaForm', 'mgcrea.ngStrap']);
145 | ```
146 | Note: Se the [ui-select dependencies](https://github.com/OptimalBPM/angular-schema-form-dynamic-select#ui-select) section for ui-select instructions
147 |
148 | # Form
149 |
150 | ASFDS is configured using form settings. There are no ASFDS-specific settings in the schema.
151 |
152 | This is to keep the schemas clean from UI-specific settings and kept usable anywhere in the solution and/or organization.
153 |
154 | ## Form types
155 |
156 | The add-on contributes the following new form types, `strapselect`, `uiselect`, `uiselectmulti`.
157 |
158 | The strapselect implements angular-strap-selects and uiselect* implements angular-ui-select.
159 |
160 | Built-in select-controls gets the bootstrap look but retain their functionality.
161 |
162 |
163 | ## Form Definition
164 | All settings reside in the form definition. See the [app.js](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/app.js) file for this example in use.
165 | ```js
166 | $scope.form = [
167 | ```
168 |
169 | ### Single select from static list
170 | The drop down items are defined by and array of value/name objects residing in the form
171 | ```js
172 | {
173 | "key": 'select',
174 | "type": 'strapselect',
175 | "titleMap": [
176 | {"value": 'value1', "name": 'text1'},
177 | {"value": 'value2', "name": 'text2'},
178 | {"value": 'value3', "name": 'text3'}
179 | ]
180 | },
181 | ```
182 | ### Multiple select from static list
183 | Like the above, but allows multiple items to be selected.
184 | ```js
185 | {
186 | "key": 'multiselect',
187 | "type": 'strapselect',
188 | "options": {
189 | "multiple": "true"
190 | }
191 | "titleMap": [
192 | {"value": 'value1', "name": 'text1'},
193 | {"value": 'value2', "name": 'text2'},
194 | {"value": 'value3', "name": 'long very very long label3'}
195 | ]
196 | },
197 | ```
198 | ### Single select from dynamically loaded list via synchronous callback function
199 | Callback must return an array of value/name objects (see static list above).
200 | The "options" structure is passed to it as a parameter.
201 | ```js
202 | {
203 | "key": "selectDynamic",
204 | "type": 'strapselect',
205 | "options": {
206 | "callback": $scope.callBackSD
207 | }
208 | },
209 | ```
210 | For examples of how the different kinds of callbacks are implemented, please look at the [relevant code in app.js](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/app.js#L18),
211 |
212 | ### Multiple select from dynamically loaded list via synchronous callback function
213 | Like strapselectdynamic above, but allowed multiple items to be selected.
214 |
215 | ```js
216 | {
217 | "key": "multiselectDynamic",
218 | "type": 'strapmultiselect',
219 | "options": {
220 | "multiple": "true"
221 | "callback": $scope.callBackMSD
222 | }
223 | },
224 | ```
225 | ### Multiple select from asynchronous callback
226 |
227 | The asyncCallback must return a *http-style promise* and the data the promise provides must be a JSON array of value/name objects.
228 |
229 |
230 | ```js
231 | {
232 | "key": "multiselectDynamicAsync",
233 | "type": 'strapselect',
234 | "options": {
235 | "multiple": "true"
236 | "asyncCallback": "callBackMSDAsync"
237 | }
238 | }
239 | },
240 | ```
241 | Note that in this example, the reference to the callback is a string, meaning a callback in the using controller scope.
242 | Also note, again, because this is a common misunderstanding, that asyncCallback should *not* return the array of items, but a http-promise, like the one $http.get()/$http.post() or [jquery's deferred.promise](https://api.jquery.com/deferred.promise/).
243 | Returning the array would be a synchronous operation, see "callback" above.
244 |
245 | ### Multiple select from dynamically loaded list via http get
246 | Convenience function, makes a get request, no need for callback.
247 | Expects the server to return a JSON array of value/name objects.
248 | ```js
249 | {
250 | "key": "multiselectDynamicHttpGet",
251 | "type": 'strapselect',
252 | "options": {
253 | "multiple": "true"
254 | "httpGet": {
255 | "url" : "test/testdata.json"
256 | }
257 | }
258 | },
259 | ```
260 | ### Multiple select from dynamically loaded list via http post with an options callback
261 | Like the get variant above function, but makes a JSON POST request passing the "parameter" as JSON.
262 | This example makes use of the optionsCallback property.
263 | It is a callback that like the others, gets the options structure
264 | as a parameter, but allows its content to be modified and returned for use in the call.
265 | Here, the otherwise mandatory httpPost.url is not set in the options but in the callback.
266 |
267 | See the [stringOptionsCallback function in app.js](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/app.js#L46) for an example.
268 | The options-instance that is passed to the parameter is a *copy* of the instance in the form,
269 | so the form instance is not affected by any modifications by the callback.
270 | ```js
271 | {
272 | "key": "multiselectDynamicHttpPost",
273 | "type": 'strapselect',
274 | "options": {
275 | "multiple": "true"
276 | "httpPost": {
277 | "optionsCallback" : "stringOptionsCallback",
278 | "parameter": { "myparam" : "Hello"}
279 | }
280 | }
281 | },
282 | ```
283 |
284 | ### Property mapping
285 | The angular-schema-form titleMap naming standard is value/name, but that is sometimes difficult to get from a server,
286 | it might not support it.
287 | Therefore, a "map"-property is provided.
288 | The property in valueProperty says in what property to look for the value, and nameProperty the name.
289 | In this case:
290 | ```js
291 | {"nodeId" : 1, "nodeName": "Test", "nodeType": "99"}
292 | ```
293 | which cannot be used, is converted into:
294 | ```js
295 | {"value" : 1, "name": "Test", "nodeId" : 1, nodeName: "Test", "nodeType": "99"}
296 | ```
297 | which is the native format with the old options retained to not destroy auxiliary information.
298 | For example, a field like "nodeType" might be used for filtering(see Filters section, below).
299 | The options for that mapping look like this:
300 | ```js
301 | {
302 | "key": "multiselectdynamic_http_get",
303 | "type": "strapselect",
304 | "options": {
305 | "multiple": "true"
306 | "httpGet": {
307 | "url": "test/testdata_mapped.json"
308 | },
309 | "map" : {"valueProperty": "nodeId", nameProperty: "nodeName"}
310 | }
311 | },
312 | ```
313 | The nameProperty can also be an array, in which case ASFDS looks for the first value.
314 | For example, in this case, one wants to first show the caption, and if that is not available, the name:
315 |
316 | ```js
317 | "map" : {"valueProperty": "nodeId", nameProperty: ["nodeCaption", "nodeName"]}
318 | ```
319 |
320 | *For more complicated mappings, and situations where the source data is
321 | in a completely different format, the callback and asyncCallback options can be used instead.*
322 |
323 | ## Filters
324 |
325 | Filters, like [conditions](https://github.com/Textalk/angular-schema-form/blob/development/docs/index.md#standard-options),
326 | handle visibility, but for each item in the options list.
327 |
328 | It works by evaluating the filter expression for each row, if it evaluates to true, the option remains in the list.
329 | One could compare it with an SQL join.
330 |
331 | The options are:
332 |
333 | * filter : An expression, evaluated in the user scope, with the "item" local variable injected. "item" is the current list item, `"model.select==item.category"`
334 | * filterTrigger : An array of expressions triggering the filtering, `"model.select"`
335 |
336 | Example:
337 | ```js
338 | {
339 | "key": 'multiselect',
340 | "type": 'strapselect',
341 | options: {
342 | "multiple": "true"
343 | "filterTriggers": ["model.select"],
344 | "filter" : "model.select==item.category"
345 | },
346 | "titleMap": [
347 | {"value": 'value1', "name": 'text1', "category": "value1"},
348 | {"value": 'value2', "name": 'text2', "category": "value1"},
349 | {"value": 'value3', "name": 'long very very long label3'}
350 | ]
351 | },
352 | ```
353 | Note on filterTrigger and why not having a watch on the entire expression:
354 |
355 | * The expression is actually a one-to-many join, and mixes two scopes in the evaluation. This might not always be handled the same by $eval.
356 | * Adding watches for the expression would mean having to add one watch for each list item, long lists would mean a huge overhead.
357 | * Also, there might be use cases where triggering should be triggered by other conditions. Or not be triggered for some other reason.
358 |
359 | ## The ASFDS controller scope
360 |
361 | One usable property that is set by ASFDS is the options.scope-attribute.
362 |
363 | Its value is the scope of the controller, which provides far-reaching control over ASFDS behavior.
364 |
365 | In the [example](https://github.com/OptimalBPM/angular-schema-form-dynamic-select/blob/master/app.js), the multiselectDynamicAsync's
366 | onChange event is implemented so that another ASFDS controller is told to repopulate its select list items when the value is changed.
367 | This is valuable, for example, when there is too much data or for some other reason, filters are inappropriate.
368 |
369 | ## Defaults and enum
370 | If a there is a form item that only has type "string" defined, but has an enum value, then a single select will be shown for that value.
371 | ```js
372 | {
373 | "key": 'select'
374 | },
375 | ```
376 | The schema declaration(the enum values will be both value and name for the options):
377 | ```js
378 | select: {
379 | title: 'Single Select Static',
380 | type: 'string',
381 | enum: ["value1", "value2", "value3"],
382 | description: 'Only single item is allowed. Based on schema enum and form default.(change here and observe how the select list below is filtered)'
383 | },
384 | ```
385 | ## inlineMaxLength and inlineMaxLengthHtml angularStrap parameters.
386 | These settings affects only [strapselect](http://mgcrea.github.io/angular-strap/#/selects-usage) and controls the number of items that are shown in the selected list of items.
387 | If that list is full, the number of list items + the test in inlineMaxLengthHtml is shown.
388 | If, for example, inlineMaxLength is set to 2 and the number of selected items is 4, the text shown will be:
389 |
390 | `4 items are too many items to show....`
391 |
392 | Example(the same as in the example file):
393 | ```js
394 | "key": 'multiselect_overflow',
395 | "type": 'strapselect',
396 | "placeholder": "Please select some items.",
397 | "options": {
398 | "multiple": "true",
399 | "inlineMaxLength": "2",
400 | "inlineMaxLengthHtml": " items are too many items to show...."
401 | },
402 | "titleMap": [
403 | {"value": 'value1', "name": 'text1'},
404 | {"value": 'value2', "name": 'text2'},
405 | {"value": 'value3', "name": 'text3'},
406 | {"value": 'value4', "name": 'text4'},
407 | ]
408 |
409 | ```
410 | ## Positioning the angularStrap select.
411 | The placement option can be used to position a [strapselect](http://mgcrea.github.io/angular-strap/#/selects). Possible values for placement are top, bottom, left, right, auto or any combination (e.g. bottom-right).
412 | Further details can be found in the [angularStrap select documentation](http://mgcrea.github.io/angular-strap/#/selects-usage).
413 |
414 | Example (the same as in the example file):
415 | ```js
416 | "key": "select_placement",
417 | "placeholder": "Please select from the right.",
418 | "options": {
419 | "placement": "right"
420 | }
421 |
422 | ```
423 | ### And then a submit button.
424 | Not needed, of course, but is commonly used.
425 | ```js
426 | {
427 | type: "submit",
428 | style: "btn-info",
429 | title: "OK"
430 | }
431 | ```
432 | And ending the form element array:
433 | ```js
434 | ];
435 | ```
436 |
437 | # Populating the list items
438 |
439 | The form.titleMap property in a form holds the list items(also in the dynamic variants).
440 | The name titleMap is the same as the built-in angular-schema-form select.
441 |
442 | ## Dynamically fetching list items
443 | These types are dynamic and fetches their data from different back ends.
444 |
445 | #### Callbacks in general
446 | Callbacks can be defined either by name(`"loadGroups"`) or absolute reference (`$scope.loadGroups`).
447 |
448 | The name is actually is an expression evaluated in the user scope that must return a function reference.
449 | This means that it *can* be `"getLoadFunctions('Groups')"`, as long as that returns a function reference.
450 |
451 | But the main reason for supporting referring to functions both by name and reference is that forms
452 | are often stored in a database and passed from the server to the client in [pure JSON format](http://stackoverflow.com/questions/2904131/what-is-the-difference-between-json-and-object-literal-notation),
453 | and there, `callback: $scope.loadGroups` is not allowed.
454 |
455 | #### Callback results
456 | The results of all callbacks can be remapped using the "map" property described above.
457 | All callbacks(also optionsCallback) has two parameters:
458 | * the options of the form,
459 | * if it is a UI-selects, the entered search value (see the UI-select example).
460 |
461 | The two kinds of callback mechanisms are:
462 |
463 | ### callback and asyncCallback
464 |
465 | * list items are fetched by a user-specified callback. The user implements the calling mechanism.
466 | * the callback receive the form options as a parameter and returns an array of list items(see the static strapselect)
467 | * asyncCallback implementations returns the data through a HttpPromise. NOT an array if items.
468 |
469 | *TIP: in an asyncCallback, you need to intercept and change an async server response before passing it on to the add-on, use the [transformResponse function](https://docs.angularjs.org/api/ng/service/$http#transforming-requests-and-responses).*
470 |
471 | ### httpGet and httpPost
472 |
473 | * list items are fetched using a built in async http mechanism, so that the user doesn't have to implement that.
474 | * the url property defines the URL to use.
475 | * the optional optionsCallback can be used to add to or change the options with information known in runtime.
476 | * httpPost-options has a "parameter"-property, that contains the JSON that will be POST:ed to the server.
477 |
478 | ### Handling errors from asynchronous callbacks
479 | For asyncCallback, httpGet and httpPost, there is an option, `onPopulationError`.
480 |
481 | If set to a callback function, and in case of a http error, the callback is called.
482 | Its parameters are: the form of the field(where they key and options are), the data and the status.
483 |
484 | See app.js for an example of its usage. Try and rename test/testdata.js and you'll see it being called.
485 |
486 | ## Statically setting the list items
487 |
488 | This is done by either using the JSON-schema enum-property, or by manually setting form.titleMap.
489 |
490 | # UI-Select
491 | The support for angular-ui-select was added in the 0.9.0-version, and is currently partial, but getting there.
492 |
493 | The currently supported UI-select specific/native options are:
494 | * Single: tagging, taggingTokens, taggingLabel, refreshDelay, searchDescription, uiClass
495 | * Multiple select: refreshDelay, uiClass, groupBy(only multiple)
496 |
497 | ## Installation
498 |
499 | UI-select is not installed by default in ASFDS, even though it is featured in the demo and example, here is how to make it work:
500 |
501 | ### Dependencies
502 |
503 | Its dependencies aren't included in the package.json, and will hence have to be installed manually, here is a script:
504 |
505 | ```bash
506 | $ bower install angular-ui-select angular-underscore underscore angular-ui-utils angular-translate angular-ui-select angular-ui-utils angular-sanitize
507 | ```
508 | ### HTML
509 | Include all relevant files:
510 | ```html
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 | ```
520 | ### Angular module configuration
521 |
522 | UI-select have several additional dependencies that need to be added to your module configuration:
523 |
524 | ```bash
525 | angular.module('yourModule', ['schemaForm', 'mgcrea.ngStrap', 'mgcrea.ngStrap.modal', 'pascalprecht.translate', 'ui.select', 'ui.highlight','mgcrea.ngStrap.select']);
526 | ```
527 |
528 |
529 | ### Forms
530 | It is used as strapselect, but by including the form types uiselect and uiselectmultiple instead.
531 | ```js
532 | {
533 | "key": 'uiselectmultiple',
534 | "type": 'uiselectmultiple',
535 | "titleMap": [
536 | { value: 'one', name: 'option one'},
537 | { value: 'two', name: 'option two'},
538 | { value: 'three', name: 'option three'}
539 | ]
540 | },
541 | ```
542 | It supports dynamically fetching items from a backend using callbacks and http-methods, but works a little bit different from AngularStrap internally, so filters, for example, aren't implemented yet.
543 |
544 | See the example app in the source for more details on how to use it.
545 |
546 | # Recommendations
547 |
548 | * Choose httpGet and httpPost over the callback and asyncCallback methods if your don't specifically need the full freedom
549 | of callback and asyncCallback. There is no reason clutter client code with http-request handling unless you have to.
550 | * Given the asynchronous nature of javascript development, try use asynchronous alternatives before synchronous that block the UI.
551 | * The way the plug-ins works, they register themselves as defaults for all matching types.
552 | As long this is the case, all relevant fields must specify the "type"-property.
553 | If not, they will get the wrong editor. Either way, it is recommended to define the type.
554 |
555 |
556 | # Building
557 |
558 | Building and minifying is done using [gulp](http://gulpjs.com/)
559 |
560 | ### Installing gulp and requrements
561 | To install gulp, you need npm to be installer, however, we want a local bower install:
562 | ```bash
563 | sudo npm install bower
564 | node_modules/bower/bin/bower install
565 | ```
566 | And then install the rest of the depencies
567 | ```bash
568 | sudo npm install
569 | ```
570 | *The instructions are for Linux, to install under windows, the same commands adjusted for windows should work*
571 |
572 | ### Running the build
573 |
574 | In the project root folder, run:
575 |
576 | ```bash
577 | $ gulp default
578 | ```
579 |
580 | # Contributing
581 |
582 | Pull requests are always very welcome. Try to make one for each thing you add, don't do [like this author(me) did](https://github.com/chengz/schema-form-strapselect/pull/2).
583 |
584 | Remember that the next version is in the develop branch, so if you want to add new features, do that there.
585 | If you want to fix a bug, do that against the master branch and it will be merged into the develop branch later.
586 |
587 |
588 |
589 | # Testing
590 |
591 | Unit testing is done using [Karma and Jasmine](http://karma-runner.github.io/0.12/intro/installation.html).
592 | The main configuration file for running tests is karma.conf.js, and test/tests.js holds the test code.
593 | First, make sure the relevant development dependencies are installed:
594 |
595 | ```bash
596 | $ npm update
597 | ```
598 |
599 | To run the tests:
600 |
601 |
602 | ```bash
603 | $ node_modules/karma/bin/karma start karma.conf.js
604 | ```
605 | # Breaking change history
606 |
607 | Important: Over the early minor versions, there has been considerable changes:
608 |
609 | * 0.3.0: all dynamic-select-related settings moved to the form.
610 | * 0.3.3: value/name-pairs for drop down data is deprecated.
611 | The correct way, and how the HTML select element actually works, is value/text.(note: Reverted in 0.8.0)
612 | The the add-on still supports both variants, but value/name will be removed.
613 | * 0.4.0: use the options.map functionality instead.
614 | * 0.5.0: Breaking changes:
615 | * http_post and http_get are renamed to httpPost and httpGet.
616 | * async.callback is removed and asyncCallback is used instead.
617 | * 0.6.0: earlier deprecated support for value/name-pairs is now removed
618 | * 0.7.0: meant a forced update of dependencies and some rewriting, since:
619 | * 2.2.1 of angular-strap has breaking changes making it impossible to keep backwards compatibility.
620 | * 0.8.0 of angular-schema-form, which also has breaking changes had to be updated to stay compatible with angular-straps' dependencies.
621 | * 0.8.0: Harmonization with angular-schema-form to be a drop-in replacement
622 | * Breaking change: The items array is now renamed to titleMap, as in ASF.
623 | * Value/name-pairs for drop-down data is now reintroduced (value/text is still supported)
624 | * 0.9.0: Breaking changes: strapselectdynamic, strapmultiselect and strapmultiselect was merged into strapselect.
625 |
626 | Note: no further API changes are planned.
627 |
628 |
629 | # History
630 |
631 | 1. This component was originally created by [chengz](https://github.com/chengz/).
632 |
633 | 2. [stevehu](https://github.com/stevehu) then added functionality to his project to connect to his [light
634 | framework](https://github.com/networknt/light).
635 |
636 | 3. This inspired [nicklasb](https://github.com/nicklasb) to merge stevehu:s code and rewrite the plugin in order to:
637 |
638 | * harmonize it with the current lookup handling in angular-schema-form
639 | * generalize it for it to be able to connect to any backend.
640 |
641 | The rest is extremely recent history(i.e. > 0.3.0).
642 |
--------------------------------------------------------------------------------
/angular-schema-form-dynamic-select.js:
--------------------------------------------------------------------------------
1 | ;(function(root, factory) {
2 | if (typeof define === 'function' && define.amd) {
3 | define(['angular-schema-form'], factory);
4 | } else if (typeof exports === 'object') {
5 | module.exports = factory(require('angular-schema-form'));
6 | } else {
7 | root.angularSchemaFormDynamicSelect = factory(root.schemaForm);
8 | }
9 | }(this, function(schemaForm) {
10 | angular.module("schemaForm").run(["$templateCache", function($templateCache) {$templateCache.put("directives/decorators/bootstrap/strap/strapmultiselect.html","