reset value or set value
andreas-stricker opened this issue · comments
I want to reset a Value or set the Value to the first option by click on a Link
my Code:
$('#myButton').click(function(){
$('select option[value="--"]').attr('selected',true);
$('select').dropkick('refresh');
});
In the select element the option is selected but the dropkick dropdown element doesn't show this option.
I also tried it with 'reset' but then dropkick displays the value which was selected at page loading and not the '--'
You need to use the dropkick methods to affect the dropkick element. Our new docs are still WIP, but the method you're looking for is the #select() method.
This would be the equivalent with jQuery:
$('select').dropkick('select', '--');
#reset() seems to be working as it should - "Resets the Dropkick and select to it's original selected options." Unless of course your option is the first one and you're using the method with the optional argument: $('select').dropkick('reset', true);
.
Also, #refresh() shouldn't really be needed here unless your original select changes drastically and the Dropkick element needs to be rebuilt.
thank you for the fast responce.
The problem ist that .dropkick('reset',true); does the same as .dropkick('reset');
It selects the original option. But i need the first option selected
If you do do $("#select").dropkick("reset");
it will reset to the originally selected option. If you do $("#select").dropkick("reset", true);
it will reset to the first option in the select.
Checkout the JSBin below to see an example :)
@strigga, if you're still having trouble, would you mind providing a JSBin recreating your issue? Everything seems to be working as expected with our tests.
hello,
i now use the JS and the CSS from the hosted CDN and now it works. i think i had an old version.
thank you!
Glad everything was sorted out. 👍