fng-ui-select 0.12.0-beta.192 → 0.12.0-beta.193

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,14 +8,14 @@ describe('Lists', function () {
8
8
  });
9
9
  it('Creates a new record with multiple shelves', function () {
10
10
  cy.visit('/#/k_referencing_self_collection/new');
11
- cy.get('#f_warehouse_name').type("m" + unique + " Warehouse");
11
+ cy.get('#f_warehouse_name').type("m".concat(unique, " Warehouse"));
12
12
  cy.get('#add_f_shelves_btn').click().click().click();
13
- cy.get('#f_shelvesList_0 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Top');
14
- cy.get('#f_shelvesList_1 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Middle');
15
- cy.get('#f_shelvesList_2 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Bottom');
13
+ cy.get('#f_shelves_location_0').type('Top');
14
+ cy.get('#f_shelves_location_1').type('Middle');
15
+ cy.get('#f_shelves_location_2').type('Bottom');
16
16
  cy.get('#add_f_items_btn').click();
17
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_description > .controls > .ng-pristine').type('Item 1');
18
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_shelf > .controls > .ng-pristine').select('Middle');
17
+ cy.get('#f_items_description_0').type('Item 1');
18
+ cy.get('#f_items_shelf_0').select('Middle');
19
19
  cy.get('#add_f_cleanedShelves').click().click();
20
20
  cy.get('#f_cleanedShelves_0').select('Middle');
21
21
  cy.get('#f_cleanedShelves_1').select('Top');
@@ -24,12 +24,12 @@ describe('Lists', function () {
24
24
  });
25
25
  it('Creates a new record with a single shelf', function () {
26
26
  cy.visit('/#/k_referencing_self_collection/new');
27
- cy.get('#f_warehouse_name').type("s" + unique + " Warehouse");
27
+ cy.get('#f_warehouse_name').type("s".concat(unique, " Warehouse"));
28
28
  cy.get('#add_f_shelves_btn').click();
29
- cy.get('#f_shelvesList_0 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Only');
29
+ cy.get('#f_shelves_location_0').type('Only');
30
30
  cy.get('#add_f_items_btn').click();
31
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_description > .controls > .ng-pristine').type('Item 1');
32
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_shelf > .controls > .ng-pristine').select('Only');
31
+ cy.get('#f_items_description_0').type('Item 1');
32
+ cy.get('#f_items_shelf_0').select('Only');
33
33
  cy.get('#add_f_cleanedShelves').click();
34
34
  cy.get('#f_cleanedShelves_0').select('Only');
35
35
  cy.get('#f_favouriteShelf').select('Only');
@@ -39,7 +39,7 @@ describe('Lists', function () {
39
39
  cy.visit('/#/l_referencing_list_in_other_document/new');
40
40
  cy.get('#f_description').type('An item in multi');
41
41
  cy.get('.select2-arrow > b').click();
42
- cy.get('.ui-select-search').type("m" + unique);
42
+ cy.get('.ui-select-search').type("m".concat(unique));
43
43
  cy.get('.select2-result-label > .ng-binding').click();
44
44
  cy.get('#f_shelf').select('Top');
45
45
  });
@@ -47,7 +47,7 @@ describe('Lists', function () {
47
47
  cy.visit('/#/l_referencing_list_in_other_document/new');
48
48
  cy.get('#f_description').type('An item in single');
49
49
  cy.get('.select2-arrow > b').click();
50
- cy.get('.ui-select-search').type("s" + unique);
50
+ cy.get('.ui-select-search').type("s".concat(unique));
51
51
  cy.get('.select2-result-label > .ng-binding').click();
52
52
  cy.get('#f_shelf').select('Only');
53
53
  });
@@ -12,12 +12,12 @@ describe('Lists', function () {
12
12
  cy.visit('/#/k_referencing_self_collection/new');
13
13
  cy.get('#f_warehouse_name').type(`m${unique} Warehouse`);
14
14
  cy.get('#add_f_shelves_btn').click().click().click();
15
- cy.get('#f_shelvesList_0 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Top');
16
- cy.get('#f_shelvesList_1 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Middle');
17
- cy.get('#f_shelvesList_2 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Bottom');
15
+ cy.get('#f_shelves_location_0').type('Top');
16
+ cy.get('#f_shelves_location_1').type('Middle');
17
+ cy.get('#f_shelves_location_2').type('Bottom');
18
18
  cy.get('#add_f_items_btn').click();
19
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_description > .controls > .ng-pristine').type('Item 1');
20
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_shelf > .controls > .ng-pristine').select('Middle');
19
+ cy.get('#f_items_description_0').type('Item 1');
20
+ cy.get('#f_items_shelf_0').select('Middle');
21
21
  cy.get('#add_f_cleanedShelves').click().click();
22
22
  cy.get('#f_cleanedShelves_0').select('Middle');
23
23
  cy.get('#f_cleanedShelves_1').select('Top');
@@ -29,10 +29,10 @@ describe('Lists', function () {
29
29
  cy.visit('/#/k_referencing_self_collection/new');
30
30
  cy.get('#f_warehouse_name').type(`s${unique} Warehouse`);
31
31
  cy.get('#add_f_shelves_btn').click();
32
- cy.get('#f_shelvesList_0 > .row-fluid > #cg_f_shelves_location > .controls > .ng-pristine').type('Only');
32
+ cy.get('#f_shelves_location_0').type('Only');
33
33
  cy.get('#add_f_items_btn').click();
34
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_description > .controls > .ng-pristine').type('Item 1');
35
- cy.get('#f_itemsList_0 > .row-fluid > #cg_f_items_shelf > .controls > .ng-pristine').select('Only');
34
+ cy.get('#f_items_description_0').type('Item 1');
35
+ cy.get('#f_items_shelf_0').select('Only');
36
36
  cy.get('#add_f_cleanedShelves').click();
37
37
  cy.get('#f_cleanedShelves_0').select('Only');
38
38
  cy.get('#f_favouriteShelf').select('Only');
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "fng-ui-select",
3
3
  "author": "Mark Chapman <support@forms-angular.org>",
4
- "version": "0.12.0-beta.192",
4
+ "version": "0.12.0-beta.193",
5
5
  "description": "angular-ui-select plugin for forms-angular",
6
6
  "repository": {
7
7
  "type": "git",
@@ -63,7 +63,8 @@
63
63
  $scope.uiSelect = $scope.uiSelect || [];
64
64
 
65
65
  $scope.windowResizeUiSelect = function (checkResize) {
66
- // This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable design choices which will be factored out later
66
+ // This is to stop the resize firing too often. Really horrible way of doing it caused by some very regrettable
67
+ // design choices which will be factored out later
67
68
  // Actually not choices - just not knowing any better
68
69
  if (!checkResize || uiSelectHelper.windowChanged($window.innerWidth, $window.innerHeight)) {
69
70
  for (var i = 0; i < $scope.uiSelect.length; i++) {
@@ -151,12 +152,12 @@
151
152
  $timeout($scope.windowResizeUiSelect);
152
153
  }]);
153
154
 
154
- uiSelectModule.directive('fngUiSelect', ['$compile', '$window', 'pluginHelper', 'cssFrameworkService', 'formMarkupHelper', 'uiSelectHelper',
155
- function ($compile, $window, pluginHelper, cssFrameworkService, formMarkupHelper, uiSelectHelper) {
155
+ uiSelectModule.directive('fngUiSelect', ['$compile', 'pluginHelper', 'cssFrameworkService', 'uiSelectHelper',
156
+ function ($compile, pluginHelper, cssFrameworkService, uiSelectHelper) {
156
157
  return {
157
158
  restrict: 'E',
158
159
  controller: 'FngUISelectCtrl',
159
- link: function (scope, element, attr) {
160
+ link: function (scope, element, attrs) {
160
161
 
161
162
  function addToConversions(path, options) {
162
163
  if (Object.keys(options).length > 0) {
@@ -174,18 +175,19 @@
174
175
  }
175
176
  }
176
177
 
177
- var processedAttr = pluginHelper.extractFromAttr(attr, 'fngUiSelect');
178
- var elemScope = angular.extend({selectId: processedAttr.info.id}, processedAttr.directiveOptions);
179
- var multi = processedAttr.info.array;
180
- var elementHtml;
181
- var input = '';
178
+ const processedAttrs = pluginHelper.extractFromAttr(attrs, 'fngUiSelect');
179
+ const id = processedAttrs.info.id;
180
+ const elemScope = angular.extend({selectId: id}, processedAttrs.directiveOptions);
181
+ const multi = processedAttrs.info.array;
182
+ let elementHtml;
183
+ let input = '';
182
184
 
183
185
  scope.uiSelect.push(elemScope);
184
- addToConversions(processedAttr.info.name, processedAttr.directiveOptions);
186
+ addToConversions(processedAttrs.info.name, processedAttrs.directiveOptions);
185
187
 
186
188
  // Sort out the theme, defaulting to select2 (so old users won't see the change). Bootstrap theme only works with Bootstrap 3
187
189
  // and not with animate (see https://github.com/angular-ui/ui-select/issues/1731 and others)
188
- var theme = processedAttr.directiveOptions.theme || 'select2';
190
+ var theme = processedAttrs.directiveOptions.theme || 'select2';
189
191
  if (theme === 'bootstrap') {
190
192
  if (cssFrameworkService.framework() !== 'bs3') {
191
193
  theme = 'select2';
@@ -202,10 +204,10 @@
202
204
 
203
205
  var multiControl = false;
204
206
  var multiStr = '';
205
- if (multi && (processedAttr.directiveOptions.fngajax || processedAttr.directiveOptions.forcemultiple)) {
207
+ if (multi && (processedAttrs.directiveOptions.fngajax || processedAttrs.directiveOptions.forcemultiple)) {
206
208
  // We need the array to be an array of objects with a x property. This tells forms-angular to convert it by
207
209
  // adding an attribute to the schema.
208
- pluginHelper.findIdInSchemaAndFlagNeedX(scope.baseSchema(), processedAttr.info.id);
210
+ pluginHelper.findIdInSchemaAndFlagNeedX(scope.baseSchema(), id);
209
211
  multiControl = true;
210
212
  } else {
211
213
  multiStr = multi ? 'multiple close-on-select reset-search-input ' : '';
@@ -213,38 +215,43 @@
213
215
 
214
216
  var requiredStr = '';
215
217
  var allowClearStr = '';
216
- if (processedAttr.info.required) {
218
+ if (processedAttrs.info.required) {
217
219
  requiredStr = ' ng-required="true"';
218
220
  } else {
219
221
  allowClearStr = ' allow-clear';
220
222
  }
221
- var disabledStr = '';
222
- if (processedAttr.directiveOptions.ngdisabled) {
223
- disabledStr = ` ng-disabled="${processedAttr.directiveOptions.ngdisabled}"`
224
- } else {
225
- disabledStr = ' ng-disabled="disabled"';
226
- }
223
+ let disabledStr = pluginHelper.genIdAndDisabledStr(scope, processedAttrs, "", true);
227
224
 
228
225
  // First of all add a hidden input field which we will use to set the width of the select
229
- if (!angular.element('#' + processedAttr.info.id + '_width-helper').length > 0) {
226
+ if (!angular.element(`#${id}_width-helper`).length > 0) {
230
227
  var hiddenInputInfo = {
231
- id: processedAttr.info.id + '_width-helper',
232
- name: processedAttr.info.name + '_width-helper',
228
+ id: `${id}_width-helper`,
229
+ name: processedAttrs.info.name + '_width-helper',
233
230
  label: ''
234
231
  };
235
- if (processedAttr.info.size) {
236
- hiddenInputInfo.size = processedAttr.info.size;
232
+ if (processedAttrs.info.size) {
233
+ hiddenInputInfo.size = processedAttrs.info.size;
237
234
  }
238
- input = pluginHelper.buildInputMarkup(scope, attr.model, hiddenInputInfo, processedAttr.options, false, multiControl, function (buildingBlocks) {
239
- return '<input id="' + hiddenInputInfo.id + '" type="text" class="form-control" disabled="" aria-label="unused input" style="position: absolute; left: -4200px;">';
240
- });
235
+ input = pluginHelper.buildInputMarkup(
236
+ scope,
237
+ attrs,
238
+ {
239
+ processedAttrs,
240
+ fieldInfoOverrides: hiddenInputInfo,
241
+ ignoreFieldInfoFromAttrs: true,
242
+ needsX: multiControl
243
+ },
244
+ function () {
245
+ return '<input id="' + hiddenInputInfo.id + '" type="text" class="form-control" disabled="" aria-label="unused input" style="position: absolute; left: -4200px;">';
246
+ }
247
+ );
241
248
  input = input.replace('class="row', 'class="hidden-row row')
242
249
  }
243
250
 
244
251
  function optionsFromArray(multiControl, multi, array, arrayGetter) {
245
252
  var isObjects = scope[array] && (scope[array].isObjects || typeof scope[array][0] === "object");
246
253
  if (isObjects) {
247
- addToConversions(processedAttr.info.name, {fngajax: uiSelectHelper.lookupFunc});
254
+ addToConversions(processedAttrs.info.name, {fngajax: uiSelectHelper.lookupFunc});
248
255
  uiSelectHelper.addClientLookup(arrayGetter, scope[array]);
249
256
  }
250
257
  var select = '';
@@ -259,54 +266,62 @@
259
266
  return select;
260
267
  }
261
268
 
262
- elementHtml = pluginHelper.buildInputMarkup(scope, attr.model, processedAttr.info, processedAttr.options, multiControl, multiControl, function (buildingBlocks) {
263
- var defaultPlaceholder = 'Select an option...';
264
- if (processedAttr.directiveOptions.fngajax) {
265
- defaultPlaceholder = 'Start typing...'
266
- }
267
- // set up the ui-select directives
268
- var select = '<ui-select ' + multiStr + buildingBlocks.common + requiredStr + disabledStr + ' theme="' + theme + '" style="min-width:18em;">'
269
- select += '<ui-select-match' + allowClearStr + ' placeholder="' + (processedAttr.info.placeholder || defaultPlaceholder) + '">';
270
-
271
-
272
- if (processedAttr.directiveOptions.fngajax) {
273
- // Stash any filters
274
- if (processedAttr.directiveOptions.fngajax !== true) {
275
- elemScope.filter = processedAttr.directiveOptions.fngajax;
269
+ elementHtml = pluginHelper.buildInputMarkup(
270
+ scope,
271
+ attrs,
272
+ {
273
+ processedAttrs,
274
+ addButtons: multiControl,
275
+ needsX: multiControl,
276
+ },
277
+ function (buildingBlocks) {
278
+ var defaultPlaceholder = 'Select an option...';
279
+ if (processedAttrs.directiveOptions.fngajax) {
280
+ defaultPlaceholder = 'Start typing...'
276
281
  }
277
- // Set up lookup function
278
- addToConversions(processedAttr.info.name, {fngajax: uiSelectHelper.lookupFunc});
279
- // Use the forms-angular API to query the referenced collection
280
- elemScope.ref = processedAttr.info.ref;
281
- scope[processedAttr.info.id + '_options'] = [];
282
- if (multiControl) {
283
- select += '{{$select.selected.text}}';
284
- } else if (processedAttr.options.subschema) {
285
- select += '{{' + attr.model + '.' + processedAttr.info.name.replace(processedAttr.options.subschemaroot, processedAttr.options.subschemaroot + '[$index]') + '.text}}';
286
- } else {
287
- select += '{{' + buildingBlocks.modelString + '.text}}';
288
- }
289
- select += '</ui-select-match>';
290
- select += '<ui-select-choices repeat="option in (' + processedAttr.info.id + '_options) track by $index" ';
291
- select += 'refresh="refreshOptions($select.search, \'' + processedAttr.info.id + '\')" ';
292
- select += 'refresh-delay="100"> ';
293
- select += '<div ng-bind-html="option.text"></div>';
294
- } else if (processedAttr.directiveOptions.deriveoptions) {
295
- if (typeof scope[processedAttr.directiveOptions.deriveoptions] === "function") {
296
- select += optionsFromArray(multiControl, multi, scope[processedAttr.directiveOptions.deriveoptions](), processedAttr.directiveOptions.deriveoptions);
282
+ // set up the ui-select directives
283
+ var select = '<ui-select ' + multiStr + buildingBlocks.common + requiredStr + disabledStr + ' theme="' + theme + '" style="min-width:18em;">'
284
+ select += '<ui-select-match' + allowClearStr + ' placeholder="' + (processedAttrs.info.placeholder || defaultPlaceholder) + '">';
285
+
286
+ if (processedAttrs.directiveOptions.fngajax) {
287
+ // Stash any filters
288
+ if (processedAttrs.directiveOptions.fngajax !== true) {
289
+ elemScope.filter = processedAttrs.directiveOptions.fngajax;
290
+ }
291
+ // Set up lookup function
292
+ addToConversions(processedAttrs.info.name, {fngajax: uiSelectHelper.lookupFunc});
293
+ // Use the forms-angular API to query the referenced collection
294
+ elemScope.ref = processedAttrs.info.ref;
295
+ scope[`${id}_options`] = [];
296
+ if (multiControl) {
297
+ select += '{{$select.selected.text}}';
298
+ } else if (processedAttrs.options.subschema) {
299
+ select += '{{' + attrs.model + '.' + processedAttrs.info.name.replace(processedAttrs.options.subschemaroot, processedAttrs.options.subschemaroot + '[$index]') + '.text}}';
300
+ } else {
301
+ select += '{{' + buildingBlocks.modelString + '.text}}';
302
+ }
303
+ select += '</ui-select-match>';
304
+ select += `<ui-select-choices repeat="option in (${id}_options) track by $index" `;
305
+ select += `refresh="refreshOptions($select.search, '${id}')" `;
306
+ select += 'refresh-delay="100"> ';
307
+ select += '<div ng-bind-html="option.text"></div>';
308
+ } else if (processedAttrs.directiveOptions.deriveoptions) {
309
+ if (typeof scope[processedAttrs.directiveOptions.deriveoptions] === "function") {
310
+ select += optionsFromArray(multiControl, multi, scope[processedAttrs.directiveOptions.deriveoptions](), processedAttrs.directiveOptions.deriveoptions);
311
+ } else {
312
+ throw new Error("In fng-ui-select " + processedAttrs.directiveOptions.deriveoptions + " is not a function on the scope");
313
+ }
314
+ } else if (processedAttrs.info.options) {
315
+ // Simple case - enumerated options on the form scope
316
+ select += optionsFromArray(multiControl, multi, processedAttrs.info.options);
297
317
  } else {
298
- throw new Error("In fng-ui-select " + processedAttr.directiveOptions.deriveoptions + " is not a function on the scope");
318
+ throw new Error('fng-ui-select has no means of populating select');
299
319
  }
300
- } else if (processedAttr.info.options) {
301
- // Simple case - enumerated options on the form scope
302
- select += optionsFromArray(multiControl, multi, processedAttr.info.options);
303
- } else {
304
- throw new Error('fng-ui-select has no means of populating select');
320
+ select += '</ui-select-choices>';
321
+ select += '</ui-select>';
322
+ return select;
305
323
  }
306
- select += '</ui-select-choices>';
307
- select += '</ui-select>';
308
- return select;
309
- });
324
+ );
310
325
  element.append($compile(input + elementHtml)(scope));
311
326
  }
312
327
  }