Copied to clipboard

Flag this post as spam?

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


  • Anne Gilmore 15 posts 66 karma points
    Jan 30, 2015 @ 14:22
    Anne Gilmore
    0

    Dynamically populating content dropdowns with content data

    Hi

    I need to populate dropdowns that appear in the content area with dynamic data rather than static lists. As I am new to Umbraco I felt that there might be someone out there who has already managed to do this, or who can offer some Sage advice - I can't seem to find anything that quite fits.

    Below is the basic tree structure where all regions, resorts and accommodations are unique, but can appear in either or both seasons.

    • Season 1
      • Regions
        • Region 1
          • Resort A
            • Accommodation 1
          • Resort B
            • Accommodation 2
            • Accommodation 3
        • Region 2
          • Resort D
            • Accommodation 6
          • Resort E
            • Accommodation 8
    • Season 2
      • Regions
        • Region 1
          • Resort A
          • Resort B
            • Accommodation 3
          • Resort C
            • Accommodation 4
            • Accommodation 5
        • Region 2
          • Resort D
            • Accommodation 7
          • Resort E
            • Accommodation 8
            • Accommodation 9

    In various content pages the editor requires a dropdown showing a list of the regions, resorts or accommodations. This only seems to be possible if I create a static list (prevalues), but as these lists change I'm reluctant to take this approach. I'd also like to be able to link the dropdowns so that if the editor selects Region 2 from the Region dropdown whilst editing a page in Season 1, a Resort dropdown will show Resorts D & E, and when Resort D is selected the Accommodation dropdown will show just Accommodation 6.

    I know I'll have to create a custom editor, it is just how do I get the dynamic data from the db? 

    In some circumstances using tags instead will solve the issues, but part of me can't believe I haven't missed something really obvious.  Has anyone got any suggestions?

    Many thanks

    Anne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Jan 30, 2015 @ 15:01
    Bjarne Fyrstenborg
    1

    Hi Anne

    I think you should be able to use content nodes as datasource by using a xpath expression when using this package: http://our.umbraco.org/projects/backoffice-extensions/content-dropdown-list

    another option might be to use nuPickers: http://our.umbraco.org/projects/backoffice-extensions/nupickers

    in the documentation for nuPickers you can see an example how to use it with the XML data source: https://github.com/uComponents/nuPickers/wiki/Data-Source-Xml and then it can be listed as 5 different types of pickers:

    • Xml CheckBox Picker
    • Xml DropDown Picker
    • Xml PrefetchList Picker
    • Xml RadioButton Picker
    • Xml TypeaheadList Picker

     

    /Bjarne

  • Anne Gilmore 15 posts 66 karma points
    Feb 02, 2015 @ 11:18
    Anne Gilmore
    0

    Hi Bjarne

    Thank you for your helpful suggestions.

    I have tried the Content Dropdown List by Northern Ground, but have not been able to populate the dropdown with anything but 'Select' which is a bit frustrating.

    However, I have had better luck with nuPickers and this actually looks as though I can relate the dropdowns - I just need to work out how.  I had come across this package before, but found the documentation confusing.  As populating the dropdowns ended up being very straightforward, I'm sure I can get this sorted if I have a play!

    Thanks for your help, very much appreciated!

    Anne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 02, 2015 @ 12:41
    Bjarne Fyrstenborg
    0

    Hi Anne

     

    Can you add the document type aliases in parentheses after the node name in your content structure and a list of which nodes to use in the dropdown or how the dropdown should be populated, then I will give it a try how you can manage to display the nodes in the dropdownlist :)

     

    /Bjarne

  • Anne Gilmore 15 posts 66 karma points
    Feb 03, 2015 @ 09:56
    Anne Gilmore
    0

    Hi Bjarne

    Your generous offer is much appreciated and I would be very interested to see your approach to this. Below is the revised content tree for one season, but the same applies to both. 

    • Season 1 (Alias: seasonNode, umbracoNaviHide: true)
      • Regions (Alias: Resorts)
        • Region 1 (Alias: Region)
          • Resort A (Alias: Resort)
            • Accommodation 1 (Alias: Accommodation)
          • Resort B (Alias: Resort)
            • Accommodation 2 (Alias: Accommodation)
            • Accommodation 3 (Alias: Accommodation)
        • Region 2 (Alias: Region)
          • Resort D (Alias: Resort)
            • Accommodation 6 (Alias: Accommodation)
          • Resort E (Alias: Resort)
            • Accommodation 8 (Alias: Accommodation)
    A content editor will need to select a region from a regional dropdown first. Based on the region they selected, the resort dropdown should only list those resorts that are in that region.  Finally, based on the resort selected the accommodation dropdown should only list accommodations for that resort.
    e.g Region dropdown would show Region 1 & 2.  If Region 2 is selected the Resort dropdown will then show only Resort D & E. If Resort E is selected only Accommodation 8 is selectable.
    As I say I have the individual dropdowns being populated correctly using nuPicker's xml Dropdown Picker, it is just working out the best way to link them.  Also this collection of linked dropdowns will be used in several content pages (& document types), so could be used in any node.  As you may have gathered this is simply a prototype so that I can play with some ideas and work out which is most suitable.  Just knowing the best way to link one dropdown with another would be a great starting point.
    Many thanks for you help.
    Anne
  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 03, 2015 @ 18:52
    Bjarne Fyrstenborg
    0

    Hi Anne

    In the following the document type aliases is Season, Regions, Region, Resort and Accommodation.

    I could populate the XML Dropdownlist by using xpath expressions like the following for the different pickers:

    Region Picker:  //Regions/*[name() ='Region'] 

    Resort Picker:  //Regions/*[name() ='Resort']

    Accommodation Picker:  //Regions/*[name() ='Accommodation'] 

    If you only need nodes for that season, you also need to check for current season, e.g. $currentPage[name() = 'Season']//*[name() = 'Accommodation'] 

    But this doesn't make the relation/link between other pickers.
    For Resort Picker I could populate it with Resort A and Resort B if Region 1 is selected, but the id is hardcoded (the id is the node id of Region 1 = selected value in Region Picker).

    $currentPage[name() = 'Season']//Region[@id = 1112]/*[name() = 'Resort'] 

    /Bjarne

  • Bjarne Fyrstenborg 1284 posts 4038 karma points MVP 8x c-trib
    Feb 03, 2015 @ 19:27
    Bjarne Fyrstenborg
    100

    For Region Picker the xpath expression could be like:

    $currentPage[name() = 'Season']//Region[@id = $currentPage/ancestor-or-self::Season/region]/*[name() = 'Resort'] 

    where the Region Picker property has alias "region" and is located on Season node.

    However when changing the value in Region Picker it requires refresh of the view, before seing changes in Resort Picker - maybe it could be done with SQL Picker, but I think it still requires a "save" before the next dropdown change it options.

    So I am not sure if there is a out-of-the-box package/property editor that handle this scenario. It it's something like this you need: http://techbrij.com/angularjs-cascade-dropdownlist-asp-net-mvc

    /Bjarne

  • Anne Gilmore 15 posts 66 karma points
    Feb 10, 2015 @ 15:27
    Anne Gilmore
    0

    Hi Bjarne

    Apologies for the delay in responding.

    The link was very helpful as Brij's approach is the concept I came up with originally and is likely to be the one I will be using.  I just thought I might be over complicating things and that there was a good chance something already existed.

    Many thanks for your help and guidance though - very much appreciated.

    Thanks

    Anne

     

Please Sign in or register to post replies

Write your reply to:

Draft