MRCollective / ChameleonForms

Shape-shifting your forms experience in ASP.NET Core MVC
MIT License
254 stars 56 forks source link

Disable empty option for required list selection for a nullable type #34

Open murdats opened 11 years ago

murdats commented 11 years ago

When a dropdown list is required, the none text should be displayed but not selectable. This can be accomplished by adding an item matching the following example

<option selected disabled style="display:none;">None Text</option>

for more information see http://stackoverflow.com/questions/5805059/select-placeholder

robdmoore commented 11 years ago

I think this is a good idea.

I also think as an extension of this, if there is a value already selected against that item then there is no point in showing the empty value at all. The way I see it, you use a nullable type for a required field when you don't want to bias the value the user selects - once they have selected a value then there is no point in showing the empty item at all.

I think the same thing applies (disable when selected, remove when a real value is selected) for displaying it as a list of radio buttons. Checkboxes are fine since the none value doesn't show up (you can uncheck everything for the same effect).

At the moment our focus is on releasing 1.0 and I would class this as a nice-to-have (since it's easy to unobtrusively do this via JavaScript and a quick look at the code I just had reveals it's actually going to be a little bit tricky to do because the built-in ASP.NET MVC helpers that we use don't make it easy to do it.

Feel free to submit a PR if you want it more urgently than in a few months. I have some initial ideas about strategies for pulling it off so if you are keen to do it then I encourage you to report back so we can discuss :)

cc @MattDavies @Royce

robdmoore commented 11 years ago

Added to Trello backlog: https://trello.com/c/Is12jfxi/130-disable-empty-option-for-required-list-selection-for-a-nullable-type-and-hide-it-altogether-after-user-has-selected-a-value