[Fixed]-Django – Get unused/all options in a select tag

1👍

No such option exists because that data isn’t sent to the server in the first place; only the selected values are.

Since you’re using JavaScript on the client side already, you could programmatically fill a hidden form field, or send the values you want to the server some other way.

The other thing to think about is, you want to have two lists, a ‘selected’ and ‘unselected’ one visually, but conceptually what you’re doing is picking multiple items from a list, which is what a single <select multiple /> is for.

It might be best to have the underlying form field be a single <select multiple /> that works normally, then build up the UI you want in JavaScript, hide the original form field from view, and update it. That way, visitors with JavaScript turned off are still going to get something that works, and it’s probably going to be easier to make it accessible too.

Leave a comment