Copied to clipboard

Flag this post as spam?

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


  • Nick 101 posts 123 karma points
    Oct 30, 2013 @ 12:03
    Nick
    0

    How to create a custom dropdown datatype with non integer option values

    Hi,

    I am trying to create a custom dropdown which will be maintained from the DataTypes section and where instead of adding a text and being assigned a random integer for the value, instead we can add a text with a value of our choice (some string or guid).

    Obviously the out of the box data types are unable to do that but I am not sure how I can build it myself.
    All the drop downs out there load their values either from the Database, Dictionaries, XML files, Files, JSon string etc.

    In my case I want to maintain the values from umbraco the same way the Umbraco dropdown files work.
    So it would look identical to what we have now, except the "value" field will also be editable the same way the text field is.

    I checked and uComponents doesn't have such a dropdown either.

    I created a use control but the DataEditorSettings do not help me create a similar interface to the existin Drop down interface.

    Any guidelines as to how to do it?

  • Nick 101 posts 123 karma points
    Oct 30, 2013 @ 12:11
    Nick
    0

    Okay one idea is to use:

    [DataEditorSetting("myCustomList", type = typeof(Values)]

    where we add our text/value pairs with a delimitor:

    Text A;guid
    Text B;guid2
    Text C;guid3

    But I'm hoping for a more elegant solution? 

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 12:19
    Hendy Racher
    0

    Hi Nick,

    Is it essential to manage the values within the datatypes section ?

    You could use the built-in XPath DropDownList and have it select from a collection of nodes, where you manage your custom property values on these nodes ?

    Or if these values don't need to be CMS managed and you'd prefer a code orientated solution how about the Enum DropDownList where you can assign whatever value to you like to an enum via attributes ?

    Hope these spark some ideas :)

    Hendy

     

  • Nick 101 posts 123 karma points
    Oct 30, 2013 @ 12:38
    Nick
    0

    These ideas are very welcome, 

    The dropdown needs to be managed by the content management team so it cannot be anything programmatical which includes enumerators, database etc and it cannot be file based xml, json etc either.

    It needs to be something within Umbraco. The custom node would work but I think it's faster and easier to add the value pair?
    In my case, each content management team manages different node paths and adding the drop down value pairs into the content tree would add a lot of permission overhead. 

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 12:44
    Hendy Racher
    0

    Hi Nick,

    Do you require a global list of text / value combinations to populate this drop down, or are they to differ for each content management team ?

    Can you give an example (perhaps there's another way to solve this problem ?)

  • Nick 101 posts 123 karma points
    Oct 30, 2013 @ 13:12
    Nick
    0

    It is global for everyone, it just needs to be maintained from the datatype menu.

    So far my solution works but it's not elegant. I add the values comma separated as my example above and then my dropdown renders using those.

    I'm just interested in knowing if there's a better/more elegant solution out there  

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 13:25
    Hendy Racher
    0

    Hi Nick, unfortunately I'm still not clear on the desired functionality - there's to be a global list of text / value options that need to be managed by content editors ideally in the developer section ? where these values are to drive a drop down list also used by content editors, or is this drop down list on the front end of the site ?

    Are you able to describe a use-case ?

  • Nick 101 posts 123 karma points
    Oct 30, 2013 @ 14:11
    Nick
    0

    I'll write very detailed steps to show you this fundamental umbraco limitation:

    Go to Umbraco -> Developer -> Data Types
    Click "Create new"
    Property Editor: Dropdown List

    Add prevalue (datatype Ntext):

    test1
    test2

    As you can see you can hover over the text and edit it, but you cannot edit the Value that umbraco decides for you.

    I want a custom dropdown list whose values are also editable.

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Oct 30, 2013 @ 14:14
    Hendy Racher
    0

    Hi Nick, I was wondering about the implementation requirements as there may be another way to solve your problem ?

  • Nick 101 posts 123 karma points
    Oct 30, 2013 @ 15:08
    Nick
    0

    I'm sure there's many ways of going around it, I could have created a custom dictionary, XML file, database table or just a node tree but this is all useless for me because I need it to be managed from the DataTypes section.

    As you have seen I have already found a solution and implemented it. I am only wondering if there is a better way. A flexible drop down list control out there, something that already exists or something someone else had come across, because being able to control the option values of your select must be a very common requirement, I would have thought. 

Please Sign in or register to post replies

Write your reply to:

Draft