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

Add a setValue method like so #53

Closed
dashfwd opened this issue Apr 10, 2012 · 1 comment
Closed

Add a setValue method like so #53

dashfwd opened this issue Apr 10, 2012 · 1 comment

Comments

@dashfwd
Copy link

dashfwd commented Apr 10, 2012

There didn't seem to be an obvious way to set the value. Here's how I hacked it to work.

  // Change the the selected value like this:
  //  $("#mySelectList").dropkick("setValue", newValue);
  methods.setValue = function(newValue) {
      var
      $select   = $(this),
      list      = $select.data('dropkick'),
      $dk       = list.$dk,
      items     = $dk.find('a');

      $(items).each(function(index, item) {
          var value =  $(item).attr("data-dk-dropdown-value");
          if (value == newValue) {
              $current = $(item).parent();;
              _setCurrent($current, $dk);
              _updateFields($current, $dk, true);
          }
      });
  }
@moestluck
Copy link

Thx was very usefull. Just one bug to fix:

$current = $(item).parent();; -> $current = $(item);
_setCurrent($current, $dk); -> _setCurrent($current.parent(), $dk);

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

3 participants