Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a dropdown menu on a form and I'd like to add the words Select option as the prevalue - so when the user first lands on the page, the menu has this value selected, I've managed to do this but the issue I have is that this is being registered as a selected value when I do a form submit. I need validation to still work e.g. Please select an option from the dropdown if Select Option is still selected.
Please select an option from the dropdown
How do I go about doing this?
One option which has come up is that I edit the dropdown code and hardcode the text. It would roll out over all dropdown menus but that's not a bad thing.
But it's a been a while since I did anything with forms myself so I have not tried theming yet - So don't know if a custom theme let's yout add this without touching some of the default files maybe?
I'm just wondering about what will happen if an upgrade is released and you make a change in the default file - I suppose it will most likely be overwritten unless you remember to undo the overwrite of course. But if it's possible to avoid this by using themes then that might even be a better way to go. But as mentioned I don't know if it's possible to use a theme for dealing with this.
Just my additional thoughts - Hope they're useful :)
Using a custom Theme (or overwriting the default) you should be able to do it (unless that's ecxactly what you did and it doesn't behave as I speculate below).
The default partial for the <select> is in ~/Views/Partials/Forms/Themes/default/Fieldtypes/FieldType.DropDownList.cshtml and just renders an empty <option value=""></option> as the first option. Keeping the value blank while adding your custom message inside should keep its behavior (99% sure, but easily tested).
Jan asks about upgrading - if you create a custom theme it will "survive" upgrades, and its possible to only copy that single file into the custom theme folder and UmbracoForms will just fallback to the default files for everything else.
Hope that helps,
Great thanks Chriztian!
@Chriztian - My comment about that was not when theming was used but if theming was not used and more to highlight that the change in the core template file would be overwritten when upgrading - But I can see I did not formulate it very well. So thank you for clarifying :)
I had this same issue today, but it was to do with the theme having <option value=""></option> at the top of the dropdown list.
But in the forms editor it has "Default Value" which I populated with "Select..." and changed
and it worked as I wanted it to, without hard coding values. It appears Model.Value is the default value but it would be good to have Model.DefaultValue instead in the API.
is working on a reply...
Write your reply to:
Image will be uploaded when post is submitted