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

Remove and Add #175

Closed
reru opened this issue Jun 4, 2013 · 6 comments
Closed

Remove and Add #175

reru opened this issue Jun 4, 2013 · 6 comments
Assignees

Comments

@reru
Copy link

reru commented Jun 4, 2013

Hi,
thank you for this great plugin. I have two select on my page and I would like to populate the second one when the user selects something from the first one. So, I need to remove all the old options and to add all the new options( I get them with ajax). I tried to use .remove() and then .add() and also .remove() and then populate, but it doesn't work. Is there a way to achieve what I want?
When I use .remove(), like in your example: $("select").data("selectBox-selectBoxIt").remove(); it removes the selectbox plugin on that select ( I have a select with no options and with the native select box graphics). Even if I remove only one option the graphics turn to normal ( no more selectboxit) and I have this errore: Cannot call method 'show' of undefined
Thank you again.

@yanickrochon
Copy link

If I may, you can simply manipulate your underlaying SELECT element and refresh it. Like so

$("#selectBoxId").empty().selectBoxIt("refresh");

and repopulate it

$("#selectBoxId").append('<option value="bleh">Bleh option</option>');  // append more as needed
// ....
$("#selectBoxId").selectBoxIt("refresh");

The function remove is the remove the entire SELECT element, not the selectBoxIt widget.

@ghost ghost assigned gfranko Jun 4, 2013
@reru
Copy link
Author

reru commented Jun 4, 2013

@yanickrochon I did what you said, but the problem is the same as before ( when I used remove) It removes the options and the graphics and it doesn't add anything...:( If I use only the last part ( the append), it appends the new option ( like add, but add keeps the selectboxit graphic), but the graphics turns normal( not the selectboxit graphic) and I still have the same error as before.
On the selectboxit page the remove function works ( it removes the options, but the graphic is the good one), so I believe that it's not like you said.
thank you for the quick answer...:)

@gfranko
Copy link
Owner

gfranko commented Jun 4, 2013

@reru Here is a jsbin that shows how you can remove all drop down options and populate a new drop down using the remove() and add() methods. Let me know if you have any questions about it!

@yanickrochon Although confusing, SelectBoxIt has it's own remove() method that is separate from the jQuery remove() method that will remove all select box options. Thanks for helping out though, I love having other people to also answer questions.

@gfranko gfranko closed this as completed Jun 4, 2013
@reru
Copy link
Author

reru commented Jun 4, 2013

It works!!! :) thank you very much! The problem was jquery...I looked at your example and I saw that you used jquery 1.8.3, on my page I had: 1.7.1 In your requirements you wrote: jQuery 1.7+, so I thought that it was ok, but it's not. You can check in your jsbin example( 1.7.1 doesn't work). I'm telling you this only to help, not to criticize such a fantastic job(your plugin)...maybe you should fix it for 1.7.1 or change the requirements.
Thank you very,very much again!!!

@gfranko gfranko reopened this Jun 4, 2013
@gfranko
Copy link
Owner

gfranko commented Jun 4, 2013

@reru Good catch! I will keep this issue open until the jQuery 1.7.1 issue is fixed. It should be fixed in the next release!

@gfranko
Copy link
Owner

gfranko commented Jun 25, 2013

I have decided to no longer fully support jQuery versions < 1.8.3 =)

@gfranko gfranko closed this as completed Jun 25, 2013
@bluesky88
Copy link

@gfranko

Hi, I am just trying using the add() methods with HTML strings which is same with the example HTML strings from populate options like below, however it still not able to read it! The reason to use HTML string is to display the label when populate the list.

Example HTML strings from populate,
// Populates the drop down using a JSON array
populate: '< option value="SelectBoxIt is:" >SelectBoxIt is:</ option >' +
'< option value="a jQuery Plugin" >a jQuery Plugin</ option >' +
'< option value="a Select Box Replacement" >a Select Box Replacement</ option >' +
'< option value="a Stateful UI Widget" >a Stateful UI Widget</ option >'

Example HTML string will use to populate,

'< optgroup label="Japan" >'+'< option value="tokyo" >Tokyo</ option >' + '</ optgroup >' +
'< optgroup label="Indonesia" >'+ '< option value="bali" >Bali</ option >' +
'< option value="Jakarta" >Jakarta</ option >' + '</ optgroup >'

How to populate new drop down with HTML strings using add() method?
Thank you so much.

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

No branches or pull requests

4 participants