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"
|
|
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('#
|
|
14
|
-
cy.get('#
|
|
15
|
-
cy.get('#
|
|
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('#
|
|
18
|
-
cy.get('#
|
|
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"
|
|
27
|
+
cy.get('#f_warehouse_name').type("s".concat(unique, " Warehouse"));
|
|
28
28
|
cy.get('#add_f_shelves_btn').click();
|
|
29
|
-
cy.get('#
|
|
29
|
+
cy.get('#f_shelves_location_0').type('Only');
|
|
30
30
|
cy.get('#add_f_items_btn').click();
|
|
31
|
-
cy.get('#
|
|
32
|
-
cy.get('#
|
|
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"
|
|
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"
|
|
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('#
|
|
16
|
-
cy.get('#
|
|
17
|
-
cy.get('#
|
|
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('#
|
|
20
|
-
cy.get('#
|
|
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('#
|
|
32
|
+
cy.get('#f_shelves_location_0').type('Only');
|
|
33
33
|
cy.get('#add_f_items_btn').click();
|
|
34
|
-
cy.get('#
|
|
35
|
-
cy.get('#
|
|
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
package/src/fng-ui-select.js
CHANGED
|
@@ -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
|
|
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', '
|
|
155
|
-
function ($compile,
|
|
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,
|
|
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
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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(
|
|
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 =
|
|
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 && (
|
|
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(),
|
|
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 (
|
|
218
|
+
if (processedAttrs.info.required) {
|
|
217
219
|
requiredStr = ' ng-required="true"';
|
|
218
220
|
} else {
|
|
219
221
|
allowClearStr = ' allow-clear';
|
|
220
222
|
}
|
|
221
|
-
|
|
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(
|
|
226
|
+
if (!angular.element(`#${id}_width-helper`).length > 0) {
|
|
230
227
|
var hiddenInputInfo = {
|
|
231
|
-
id:
|
|
232
|
-
name:
|
|
228
|
+
id: `${id}_width-helper`,
|
|
229
|
+
name: processedAttrs.info.name + '_width-helper',
|
|
233
230
|
label: ''
|
|
234
231
|
};
|
|
235
|
-
if (
|
|
236
|
-
hiddenInputInfo.size =
|
|
232
|
+
if (processedAttrs.info.size) {
|
|
233
|
+
hiddenInputInfo.size = processedAttrs.info.size;
|
|
237
234
|
}
|
|
238
|
-
input = pluginHelper.buildInputMarkup(
|
|
239
|
-
|
|
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(
|
|
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(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
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
|
-
//
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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(
|
|
318
|
+
throw new Error('fng-ui-select has no means of populating select');
|
|
299
319
|
}
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
select
|
|
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
|
-
|
|
307
|
-
select += '</ui-select>';
|
|
308
|
-
return select;
|
|
309
|
-
});
|
|
324
|
+
);
|
|
310
325
|
element.append($compile(input + elementHtml)(scope));
|
|
311
326
|
}
|
|
312
327
|
}
|