Skip to content

Commit

Permalink
update existing labels pointing to the original input/select to point…
Browse files Browse the repository at this point in the history
… to the selectize input/select selectize#658
  • Loading branch information
barretts authored and joallard committed Jul 27, 2016
1 parent 5a59ef6 commit e6fb783
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ $.extend(Selectize.prototype, {
var timeout_focus;
var classes;
var classes_plugins;
var inputId;

inputMode = self.settings.mode;
classes = $input.attr('class') || '';
Expand All @@ -126,6 +127,11 @@ $.extend(Selectize.prototype, {
$dropdown = $('<div>').addClass(settings.dropdownClass).addClass(inputMode).hide().appendTo($dropdown_parent);
$dropdown_content = $('<div>').addClass(settings.dropdownContentClass).appendTo($dropdown);

if(inputId = $input.attr('id')) {
$control_input.attr('id', inputId + '_selectized');
$('label[for='+inputId+']').attr('for', inputId + '_selectized');
}

if(self.settings.copyClassesToDropdown) {
$dropdown.addClass(classes);
}
Expand Down
39 changes: 39 additions & 0 deletions test/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,45 @@

});

describe('clicking label', function() {

it('should give it focus to select', function(done) {
var inputId = "labeledSelect";
$('#fixture').append('<label for="'+inputId+'">select</label>');
var label = $('label[for="'+inputId+'"]');

var test = setup_test('<select id="'+inputId+'">' +
'<option value="a">A</option>' +
'<option value="b">B</option>' +
'</select>', {});

Syn
.click(label)
.delay(0, function() {
label.remove();
expect(test.selectize.isFocused).to.be.equal(true);
done();
});
});

it('should give it focus to input', function(done) {
var inputId = "labeledInput";
$('#fixture').append('<label for="'+inputId+'">input</label>');
var label = $('label[for="'+inputId+'"]');

var test = setup_test('<input id="'+inputId+'" type="text" value="a,b,c,d">', {});

Syn
.click(label)
.delay(0, function() {
label.remove();
expect(test.selectize.isFocused).to.be.equal(true);
done();
});
});

});

describe('clicking option', function() {

it('should select it', function(done) {
Expand Down

0 comments on commit e6fb783

Please sign in to comment.