Add destroy() or remove()
Closed this issue · 4 comments
I need recreate a cascadingdropdown because I can't reload the source (including selected defaults).
Can you help-me?
Sorry, english is not my language.
Ps: My cascadingdropdown is create after the user scan the barcode, in the first time, this work great. But if the user, scan a new barcode, the dropdown don't update the source (in console, I can't see the ajax call). Its possible update all sources of cascadingdropdown or destroy him to recreate again.
Is it possible for you to create a jsFiddle or something so I can see exactly what you're trying to do? I understand you're trying to update the dropdown source when something changes. Maybe you can try something like this, assuming I understand your problem correctly:
var sourceUrl = "/api/product/get";
// method that is triggered when a scan is done
function updateSourceUrl(productId) {
sourceUrl += "/" + productId;
}
$("#myDropdowns").cascadingDropdown({
selectBoxes: [
{
selector: ".step1",
source: function(request, response) {
$.getJSON(sourceUrl, request, function(data) {
// do stuff with the data
});
}
}
]
});
Please let me know if that's what you were looking for.
On a side note, it would be a good idea to add a .destroy()
method to remove the plugin altogether.
I think I can see the issue that @FredWTaylor is having, as I've run into some problems as well.
I have my cascading dropdowns in a modal, which is opened when a button is clicked. Depending what button is clicked, I need to select different values in the dropdowns. However, once cascadingDropdown
is applied to a group, it doesn't seem to reinitialise the options, even when you re-apply it.
selected: $button.data('id')
should use the id
data attr of the button that's clicked, but once $dropdowns.cascadingDropdown(options)
is fired, that's set in stone - if I re-apply $dropdowns.cascadingDropdown(options)
when the button is clicked, the new data attr isn't picked up.
It's difficult to explain what I'm trying to do, and what I'm finding, and I've had trouble getting the plugin working on JSFiddle to setup an example.
Maybe adding a destroy()
method would allow it to re-initialise with new options, or being able to grab the required selected
option from a data attr on the dropdown would allow changes on the fly?
I've updated the issue to better represent what needs to be done.
Thanks for contributing :-)