Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Owain Williams 312 posts 920 karma points MVP c-trib
    1 week ago
    Owain Williams
    0

    How to add - Select - text in dropdown menu

    Hi,

    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.

    How do I go about doing this?

    O.

  • Owain Williams 312 posts 920 karma points MVP c-trib
    1 week ago
    Owain Williams
    0

    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.

  • Jan Skovgaard 11143 posts 22746 karma points MVP 4x admin c-trib
    1 week ago
    Jan Skovgaard
    0

    Hi Owain

    I think that is probably the best and most consistent solution since I can't imagine a scenario where you would have it any different anyway? Sounds like a more clean approach rather than fiddling around with JavaScript and messing around with the DOM :)

    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 :)

    /Jan

  • Chriztian Steinmeier 2668 posts 7946 karma points MVP 2x admin c-trib
    1 week ago
    Chriztian Steinmeier
    101

    Hi Owain,

    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).

    EDIT: 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,

    /Chriztian

  • Owain Williams 312 posts 920 karma points MVP c-trib
    1 week ago
    Owain Williams
    0

    Great thanks Chriztian!

  • Jan Skovgaard 11143 posts 22746 karma points MVP 4x admin c-trib
    1 week ago
    Jan Skovgaard
    0

    @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 :)

    /Jan

Please Sign in or register to post replies

Write your reply to:

Draft