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

Bug, selected: $this.is(':selected') #51

Open
jaswrks opened this issue Feb 17, 2014 · 0 comments
Open

Bug, selected: $this.is(':selected') #51

jaswrks opened this issue Feb 17, 2014 · 0 comments

Comments

@jaswrks
Copy link

jaswrks commented Feb 17, 2014

From ddSlick source code...

//Get data from HTML select options
obj.find('option').each(function () {
  var $this = $(this), thisData = $this.data();
  ddSelect.push({
      text: $.trim($this.text()),
      value: $this.val(),
      selected: $this.is(':selected'),
      description: thisData.description,
      imageSrc: thisData.imagesrc //keep it lowercase for HTML5 data-attributes
  });
});

I believe this could be causing a problem. selected: $this.is(':selected') will return true for the first item in the list when there is no selected="selected" attribute (i.e. even when there is nothing truly selected yet). This is jQuery being smart.

However, in the context of your jQuery plugin, this causes a problem, because there is no way to use the selectText config option if selected: $this.is(':selected') always returns at least one true value.


Suggested Fix

//Get data from HTML select options
obj.find('option').each(function (index) {
  var $this = $(this), thisData = $this.data();
  ddSelect.push({
      text: $.trim($this.text()),
      value: $this.val(),
      selected: obj[0].selectedIndex === index,
      description: thisData.description,
      imageSrc: thisData.imagesrc //keep it lowercase for HTML5 data-attributes
  });
});

Parts changed: function (index) and selected: obj[0].selectedIndex === index,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant