Copied to clipboard

Flag this post as spam?

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


  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Dec 04, 2009 @ 11:28
    Tim
    1

    Separate name/values for dropdown lists

    Hi,

    I'm having a play with Contour, with the aim of possibly using it for some upcoming umbraco based projects. I have a couple of questions.

    1) Is it possible to have separate key/values for dropdown lists, e.g. have an enquiry type dropdown, with things like 'General', 'Sales' etc, and then have the values as the relevant email addresses for those types of enquiries?

    2) Following on from this, is it possible to send the confirmation email that I define in the workflows to the selected email value? The documentation on the website mentions using placeholders for the field names, can they also be used to route the emails?

  • Dan Evans 629 posts 1016 karma points
    Dec 08, 2009 @ 12:16
    Dan Evans
    0

    Did you work out a solution to this? I'm trying to achieve the same thing.

    Also, ideally i'd like to mask the email addresses so they are not in the actual form.

    Thanks

    Dan

  • Dan Evans 629 posts 1016 karma points
    Dec 08, 2009 @ 12:25
    Dan Evans
    0

    As far as i can tell Ultimate Picker would be the way to go to keep the data in Umbraco but this only specifies a name. I don't think you can specify the value as this will be the page id of the page. Would be good if this data type allowed you to specify both.

    The other option which i think i'll go for is to usea SQL database as a prevalue data source. My contacts are not going to change very often so i'll just create a 2 column table to store the information.

    d

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Dec 08, 2009 @ 13:22
    Tim
    0

    Hi Dan,

    I'm still looking into this, am investigating creating a custom field type that supports name/value pairs, but I'm still in the very early stages on this one, I'll let you know if I get something working!

    Have you managed to get a dropdown list to display names and values with the sql data source? How did you do it?

  • Dan Evans 629 posts 1016 karma points
    Dec 08, 2009 @ 18:06
    Dan Evans
    0

    I haven't tried yet but when you choose SQL data source it asks which column is the name and which the value so should be pretty easy to do.

    There's still the additional problem that i don't really want to put the email addresses in the form so really we need 3 columns and some way of translating a code to an email address but that's a different problem i think!

  • Dan Evans 629 posts 1016 karma points
    Dec 09, 2009 @ 17:27
    Dan Evans
    0

    Using a SQL datasource works however Courier sorts the data alphabetically by the key which is not what i want. Is there a way for it just to use the pre-values in the order they come out of the database?

  • Tim 1193 posts 2675 karma points MVP 3x c-trib
    Dec 11, 2009 @ 13:30
    Tim
    0

    I've come up with a workaround that works, it's not very elegant, but it gets the job done, until this particular bit of functionality is available out of the box!

    My field items aren't going to change that often, so I've added a dropdown with just the text values, and created a custom workflow item that allows me to do a switch statement on the selected value, and route the emails acordingly. It also means I get control over the ordering of the fields in the email that gets generated, and I can also add in some extra information ot the email, like the name of the page that the form was submitted on, and some data to do with referers that we log on the site for SEO purposes.

    I'm not sure about the ordering in the list (I think the list items should have a sort order, like the pages in the main cms, maybe that'll get implemented in a later version). But you could use the custom workflow to query the database and lookup the emails. If you grab the developer docs from the contour page there's an example workflow item in the back, I just pulled that to bits and used it to base mine on.

  • Mark Bowser 273 posts 860 karma points c-trib
    Aug 06, 2015 @ 20:48
    Mark Bowser
    0

    This is still something I'm working on. Client needs to be able to manage the display names of the options separately from the values. Since it is something that the client needs to be able to manage, it makes the workflow option less appealing.

    Anyone have any other ideas?

  • Mark Bowser 273 posts 860 karma points c-trib
    Aug 06, 2015 @ 22:48
    Mark Bowser
    1

    I came up with a relatively painless solution. I am using Umbraco 7.1.8 and Contour 3.0.20. I'm pretty sure this solution wouldn't be very difficult to adapt to the new Umbraco.Forms. For larger dropdowns, adjustments would need to be made, but this is a good start.

    I created a new FieldType that I called the "Enhanced DropDownList". This is what it looked like in the backoffice:

    enter image description here

    I didn't use the default Prevalue Sources because I wasn't confident that I could get the value and display text out without doing something really hacky feeling. This took very little work. I had to create two files.

    This is the FieldType. It doesn't have anything special. I have it a DefaultValue and a TextArea where I could enter the option values as csv.

    public sealed class EnhancedDropDownList : FieldType
    {
    
        [global::Umbraco.Forms.Core.Attributes.Setting("Comma-separated values. The first value is the value that will be submitted. The second value is the display name.", control = "Umbraco.Forms.Core.FieldSetting.TextArea", description = "The first value is the value that will be submitted. The second value is the display name.")]
        public string PreValues { get; set; }
    
        [global::Umbraco.Forms.Core.Attributes.Setting("Default Value", control = "Umbraco.Forms.Core.FieldSetting.TextField", description = "Default value of the dropdownlist")]
        public string DefaultValue { get; set; }
    
        public EnhancedDropDownList()
        {
            Name = "Enhanced Drop Down List";
            Id = new Guid("10942e58-4e0f-4e5c-8371-14e32ca2c571");
            Description = "DropDownList with extra features";
            Icon = "dropdownlist.png";
            DataType = FieldDataType.String;
        }
    
        public override string RenderPreview()
        {
            return "<select><option value=\"\"></option></select>";
        }
    
        public override string RenderPreviewWithPrevalues(List<object> prevalues)
        {
            return RenderPreview();
        }
    }
    

    This is the View. It lives in /umbraco/Plugins/umbracoContour/Views/FieldType.EnhancedDropDownList.cshtml. It needs to be named, so it matches the FieldType created above. I basically copied the existing FieldType.DropDownList.cshtml, but parsed my csv values and used those to generate the <option> tags.

    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    
    @{
        var mandatoryAttributes = string.Format("data-val=\"true\" data-val-required=\"{0}\"", Model.RequiredErrorMessage);
        var defaultValue = Model.AdditionalSettings.First(s => s.Key == "DefaultValue").Value;
        var optionData = Model.AdditionalSettings.First(s => s.Key == "PreValues").Value;
        var options = optionData.Split('\n');
    }
    
    <select name="@Model.Name" id="@Model.Id" @(Model.Mandatory ? @mandatoryAttributes : "")>
        <option value="">@defaultValue</option>
        @foreach (var option in options)
        {
            var optionValue = option.Split(',')[0];
            var displayName = option.Split(',')[1];
            var isSelected = Model.ContainsValue(optionValue);
            if (isSelected)
            {
                <option value="@optionValue" selected="selected">@displayName</option>
            }
            else
            {
                <option value="@optionValue">@displayName</option>
            }
        }
    </select>
    
Please Sign in or register to post replies

Write your reply to:

Draft