Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 04b9752

Browse files
committed
Merge pull request #1220 from arkarkark/ark-fix-input-id
add input id to search <input> if present on ui-select directive as input-id
2 parents f5260ea + 7917e56 commit 04b9752

File tree

2 files changed

+35
-16
lines changed

2 files changed

+35
-16
lines changed

src/uiSelectDirective.js

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ uis.directive('uiSelect',
1919

2020
//Multiple or Single depending if multiple attribute presence
2121
if (angular.isDefined(tAttrs.multiple))
22-
tElement.append("<ui-select-multiple/>").removeAttr('multiple');
22+
tElement.append('<ui-select-multiple/>').removeAttr('multiple');
2323
else
24-
tElement.append("<ui-select-single/>");
24+
tElement.append('<ui-select-single/>');
25+
26+
if (tAttrs.inputId)
27+
tElement.querySelectorAll('input.ui-select-search')[0].id = tAttrs.inputId;
2528

2629
return function(scope, element, attrs, ctrls, transcludeFn) {
2730

@@ -43,7 +46,7 @@ uis.directive('uiSelect',
4346

4447
$select.onSelectCallback = $parse(attrs.onSelect);
4548
$select.onRemoveCallback = $parse(attrs.onRemove);
46-
49+
4750
//Limit the number of selections allowed
4851
$select.limit = (angular.isDefined(attrs.limit)) ? parseInt(attrs.limit, 10) : undefined;
4952

@@ -56,8 +59,8 @@ uis.directive('uiSelect',
5659

5760
if(attrs.tabindex){
5861
attrs.$observe('tabindex', function(value) {
59-
$select.focusInput.attr("tabindex", value);
60-
element.removeAttr("tabindex");
62+
$select.focusInput.attr('tabindex', value);
63+
element.removeAttr('tabindex');
6164
});
6265
}
6366

test/select.spec.js

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ describe('ui-select tests', function() {
7878
{ name: 'Nicole', email: '[email protected]', group: 'bar', age: 43 },
7979
{ name: 'Natasha', email: '[email protected]', group: 'Baz', age: 54 }
8080
];
81-
81+
8282
scope.peopleObj = {
8383
'1' : { name: 'Adam', email: '[email protected]', age: 12, country: 'United States' },
8484
'2' : { name: 'Amalie', email: '[email protected]', age: 12, country: 'Argentina' },
@@ -127,6 +127,7 @@ describe('ui-select tests', function() {
127127
if (attrs.title !== undefined) { attrsHtml += ' title="' + attrs.title + '"'; }
128128
if (attrs.appendToBody !== undefined) { attrsHtml += ' append-to-body="' + attrs.appendToBody + '"'; }
129129
if (attrs.allowClear !== undefined) { matchAttrsHtml += ' allow-clear="' + attrs.allowClear + '"';}
130+
if (attrs.inputId !== undefined) { attrsHtml += ' input-id="' + attrs.inputId + '"'; }
130131
}
131132

132133
return compileTemplate(
@@ -207,7 +208,7 @@ describe('ui-select tests', function() {
207208
//uisRepeatParser
208209

209210
it('should parse simple repeat syntax', function() {
210-
211+
211212
var locals = {};
212213
locals.people = [{name: 'Wladimir'}, {name: 'Samantha'}];
213214
locals.person = locals.people[0];
@@ -226,7 +227,7 @@ describe('ui-select tests', function() {
226227
});
227228

228229
it('should parse simple repeat syntax', function() {
229-
230+
230231
var locals = {};
231232
locals.people = [{name: 'Wladimir'}, {name: 'Samantha'}];
232233
locals.person = locals.people[0];
@@ -239,7 +240,7 @@ describe('ui-select tests', function() {
239240
});
240241

241242
it('should parse simple property binding repeat syntax', function() {
242-
243+
243244
var locals = {};
244245
locals.people = [{name: 'Wladimir'}, {name: 'Samantha'}];
245246
locals.person = locals.people[0];
@@ -252,7 +253,7 @@ describe('ui-select tests', function() {
252253
});
253254

254255
it('should parse (key, value) repeat syntax', function() {
255-
256+
256257
var locals = {};
257258
locals.people = { 'WC' : {name: 'Wladimir'}, 'SH' : {name: 'Samantha'}};
258259
locals.person = locals.people[0];
@@ -272,7 +273,7 @@ describe('ui-select tests', function() {
272273
});
273274

274275
it('should parse simple property binding with (key, value) repeat syntax', function() {
275-
276+
276277
var locals = {};
277278
locals.people = { 'WC' : {name: 'Wladimir'}, 'SH' : {name: 'Samantha'}};
278279
locals.person = locals.people['WC'];
@@ -286,7 +287,7 @@ describe('ui-select tests', function() {
286287
});
287288

288289
it('should should accept a "collection expresion" only if its not (key, value) repeat syntax', function() {
289-
290+
290291
var locals = {};
291292
locals.people = { 'WC' : {name: 'Wladimir'}, 'SH' : {name: 'Samantha'}};
292293
locals.person = locals.people['WC'];
@@ -299,7 +300,7 @@ describe('ui-select tests', function() {
299300
});
300301

301302
it('should should throw if "collection expresion" used and (key, value) repeat syntax', function() {
302-
303+
303304
var locals = {};
304305
locals.people = { 'WC' : {name: 'Wladimir'}, 'SH' : {name: 'Samantha'}};
305306
locals.person = locals.people['WC'];
@@ -339,7 +340,7 @@ describe('ui-select tests', function() {
339340

340341
expect(getMatchLabel(el)).toEqual('Adam');
341342
});
342-
343+
343344
it('should correctly render initial state with track by feature', function() {
344345
var el = compileTemplate(
345346
'<ui-select ng-model="selection.selected"> \
@@ -447,13 +448,13 @@ describe('ui-select tests', function() {
447448
it('should toggle allow-clear directive', function() {
448449
scope.selection.selected = scope.people[0];
449450
scope.isClearAllowed = false;
450-
451+
451452
var el = createUiSelect({theme : 'select2', allowClear: '{{isClearAllowed}}'});
452453
var $select = el.scope().$select;
453454

454455
expect($select.allowClear).toEqual(false);
455456
expect(el.find('.select2-search-choice-close').length).toEqual(0);
456-
457+
457458
// Turn clear on
458459
scope.isClearAllowed = true;
459460
scope.$digest();
@@ -1506,6 +1507,7 @@ describe('ui-select tests', function() {
15061507
if (attrs.closeOnSelect !== undefined) { attrsHtml += ' close-on-select="' + attrs.closeOnSelect + '"'; }
15071508
if (attrs.tagging !== undefined) { attrsHtml += ' tagging="' + attrs.tagging + '"'; }
15081509
if (attrs.taggingTokens !== undefined) { attrsHtml += ' tagging-tokens="' + attrs.taggingTokens + '"'; }
1510+
if (attrs.inputId !== undefined) { attrsHtml += ' input-id="' + attrs.inputId + '"'; }
15091511
}
15101512

15111513
return compileTemplate(
@@ -2093,6 +2095,20 @@ describe('ui-select tests', function() {
20932095

20942096
expect($(el).scope().$select.selected.length).toBe(5);
20952097
});
2098+
2099+
it('should add an id to the search input field', function () {
2100+
var el = createUiSelectMultiple({inputId: 'inid'});
2101+
var searchEl = $(el).find('input.ui-select-search');
2102+
expect(searchEl.length).toEqual(1);
2103+
expect(searchEl[0].id).toEqual('inid');
2104+
});
2105+
});
2106+
2107+
it('should add an id to the search input field', function () {
2108+
var el = createUiSelect({inputId: 'inid'});
2109+
var searchEl = $(el).find('input.ui-select-search');
2110+
expect(searchEl.length).toEqual(1);
2111+
expect(searchEl[0].id).toEqual('inid');
20962112
});
20972113

20982114
describe('default configuration via uiSelectConfig', function() {

0 commit comments

Comments
 (0)