Copied to clipboard

Flag this post as spam?

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


  • Simon 692 posts 1068 karma points
    Jan 28, 2015 @ 17:24
    Simon
    0

    Contour DropDownList select value by default

    Hi friends,

    Can someone help figure it out how can I set a particular value of a dropdownlist to be selected by default in the form.

    For exmaple, I have a dropdown list with these values

    • Select
    • Option 1
    • Option 2
    How can I told contour to select by default the value 'Select' as the pre-select value?
    Thank you in advance.
    Regards

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 28, 2015 @ 19:16
    Dennis Aaen
    102

    Hi Simon.

    I have found a way how you can do it, but you need to modify the view for the FieldType.DropDownList. In Contour have have the option to set an default value. like the screenshot shows below. The FieldType.DropDownList.cshtml file is located here: /Umbraco/Plugins/umbracoContour/Views

    To get this working for DropDownList, you simply need to add @Model.Value to the empty option tag.

    So you simply change this:

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    <select name="@Model.Name" id="@Model.Id"
    @if (Model.Mandatory){<text> data-val="true" data-val-required="@Model.RequiredErrorMessage"</text>}
    >
        <option value=""></option>
        @foreach (var pv in Model.PreValues)
        {
            <option value="@pv.Value"
            @if (Model.ContainsValue(pv.Value))
            {<text>selected="selected"</text>}
            >@pv.Value</option>
        }
    </select>

    To the following:

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    <select name="@Model.Name" id="@Model.Id"
    @if (Model.Mandatory){<text> data-val="true" data-val-required="@Model.RequiredErrorMessage"</text>}
    >
        <option value="">@Model.Value</option>
        @foreach (var pv in Model.PreValues)
        {
            <option value="@pv.Value"
            @if (Model.ContainsValue(pv.Value))
            {<text>selected="selected"</text>}
            >@pv.Value</option>
        }
    </select>

    Just keep in mind that you maybe need to do these changes again if you update Contour to a newer version late on.

    Hope this helps,

    /Dennis

  • Simon 692 posts 1068 karma points
    Jan 29, 2015 @ 09:42
    Simon
    0

    Thank you Dennis.

    Appreciate your help!

    I will try it out.

    Regards

  • Simon 692 posts 1068 karma points
    Jan 29, 2015 @ 09:55
    Simon
    0

    It worked :)

    Thanks

  • Dennis Aaen 4499 posts 18254 karma points admin hq c-trib
    Jan 29, 2015 @ 10:05
    Dennis Aaen
    0

    Hi Simon,

    You´re welcome. Happy that I could help you. - Could you please mark the questions as solved. You do it by clicking the little green tick in my post. What this does is the question is mark as solved, and people that came accross this post can go directly to the solution, and see what worked for you.

    Keep in mind that you can´t change the marked question once you have set it.

    And once again, happy that it worked for you.

    /Dennis

  • sulkhan 2 posts 71 karma points
    Sep 28, 2015 @ 10:18
    sulkhan
    0

    hey dennis i need ur help i must make a web site about car sales and buying and i need all catecories and models about cars maybe someone have it written and gives me pls :S

  • Simon 692 posts 1068 karma points
    Jan 29, 2015 @ 10:26
    Simon
    0

    Cheers

  • sulkhan 2 posts 71 karma points
    Sep 28, 2015 @ 10:17
    sulkhan
    0

    hey boys i need ur help i must make a web site about car sales and buying and i need all catecories and models about cars maybe someone have it written and gives me pls :S

  • Matthew Kirschner 323 posts 611 karma points
    Dec 03, 2015 @ 18:45
    Matthew Kirschner
    0

    This worked like a charm and seems to be the intended functionality of the DropDownList. Perhaps this update should make its way to Umbraco Forms core.

Please Sign in or register to post replies

Write your reply to:

Draft