Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make label[for] work with selectized input #755

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/selectize.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ $.extend(Selectize.prototype, {
var tab_index;
var classes;
var classes_plugins;
var inputId;

inputMode = self.settings.mode;
tab_index = $input.attr('tabindex') || '';
Expand All @@ -118,6 +119,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
41 changes: 40 additions & 1 deletion test/interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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+'"]');

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: While I was poking through your branch, I noticed a lot of extra WS on this line :)

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 Expand Up @@ -237,7 +276,7 @@
expect(selectize.getItem(text).length).to.be.equal(0);
expect($(selectize.$dropdown_content).filter('.create').length).to.be.equal(0);
});
});
});

});

Expand Down