From e6fb78344eba7a7a3dfc77bd18d2fb4eb4e682b7 Mon Sep 17 00:00:00 2001 From: Barrett Sonntag Date: Thu, 2 Apr 2015 13:35:49 -0500 Subject: [PATCH 1/2] update existing labels pointing to the original input/select to point to the selectize input/select #658 --- src/selectize.js | 6 ++++++ test/interaction.js | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/src/selectize.js b/src/selectize.js index 1e04c20cd..0d7b3aa04 100644 --- a/src/selectize.js +++ b/src/selectize.js @@ -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') || ''; @@ -126,6 +127,11 @@ $.extend(Selectize.prototype, { $dropdown = $('
').addClass(settings.dropdownClass).addClass(inputMode).hide().appendTo($dropdown_parent); $dropdown_content = $('
').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); } diff --git a/test/interaction.js b/test/interaction.js index e3c49eb93..0ec1578c8 100644 --- a/test/interaction.js +++ b/test/interaction.js @@ -100,6 +100,45 @@ }); + describe('clicking label', function() { + + it('should give it focus to select', function(done) { + var inputId = "labeledSelect"; + $('#fixture').append(''); + var label = $('label[for="'+inputId+'"]'); + + var test = setup_test('', {}); + + 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(''); + var label = $('label[for="'+inputId+'"]'); + + var test = setup_test('', {}); + + 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) { From 645e04a7c5d27147e7919cfd8a3ade1ad2079d00 Mon Sep 17 00:00:00 2001 From: Jonathan Allard Date: Wed, 27 Jul 2016 18:07:40 -0400 Subject: [PATCH 2/2] Corrections on #755 - Correct tests - Use hyphen instead of underscore in new node id --- src/selectize.js | 4 ++-- test/interaction.js | 16 +++++++--------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/selectize.js b/src/selectize.js index 0d7b3aa04..54d56bc4b 100644 --- a/src/selectize.js +++ b/src/selectize.js @@ -128,8 +128,8 @@ $.extend(Selectize.prototype, { $dropdown_content = $('
').addClass(settings.dropdownContentClass).appendTo($dropdown); if(inputId = $input.attr('id')) { - $control_input.attr('id', inputId + '_selectized'); - $('label[for='+inputId+']').attr('for', inputId + '_selectized'); + $control_input.attr('id', inputId + '-selectized'); + $('label[for='+inputId+']').attr('for', inputId + '-selectized'); } if(self.settings.copyClassesToDropdown) { diff --git a/test/interaction.js b/test/interaction.js index 0ec1578c8..37b446a3a 100644 --- a/test/interaction.js +++ b/test/interaction.js @@ -104,16 +104,15 @@ it('should give it focus to select', function(done) { var inputId = "labeledSelect"; - $('#fixture').append(''); - var label = $('label[for="'+inputId+'"]'); + var label = + $('').appendTo('form'); var test = setup_test('', {}); - Syn - .click(label) + syn.click(label) .delay(0, function() { label.remove(); expect(test.selectize.isFocused).to.be.equal(true); @@ -123,13 +122,12 @@ it('should give it focus to input', function(done) { var inputId = "labeledInput"; - $('#fixture').append(''); - var label = $('label[for="'+inputId+'"]'); - + var label = + $('').appendTo('form'); + var test = setup_test('', {}); - Syn - .click(label) + syn.click(label) .delay(0, function() { label.remove(); expect(test.selectize.isFocused).to.be.equal(true);