Copied to clipboard

Flag this post as spam?

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


  • Tim C 161 posts 528 karma points
    May 13, 2016 @ 10:24
    Tim C
    0

    Two custom property editors communicating?

    I would like to have a document type with two drop downs, the second one's options changing whenever a value is selected in the first one.

    My idea is to build a custom property editor for the second : can I access the first one's selectedIndex / value onchange in the controller for the second and rebuild its options somehow?

    The first one can be a standard drop down from the Umbraco core editors or if neccessary, also a custom one.

    ALso I would like to store the relationshiip between the two as JSON in the prevalues of the second.

    Is this do-able? Any pointers would be appreciated.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 15, 2016 @ 20:20
    Jan Skovgaard
    0

    Hi Tim

    I think the easiest for you would be to build one custom property editor with two dropdowns in it so you have direct access to the values in the scope of your property editor instead. I have a feeling that this approach will save you quite a headache figuring out how to best fetch the value from the custom Umbraco dropdown etc. - Not that it can't be done...it can but the approach you would need to take does not feel right to me. I really think that it would be much more easy for you to handle it with simply one property editor.

    Just my 2 cents :)

    /Jan

  • Tim C 161 posts 528 karma points
    May 16, 2016 @ 08:13
    Tim C
    0

    Jan

    I like the sound of this!

    However, I want to save both select values to the cms.

    Would I have to manually control model.value (ie make it into some JSON containing both values) based on an onchange event from both dropdowns?

    If I do this, can I then access the JSON and the individual values from Razor eg in a view fetching documents based on the values contained in these dropdowns?

    Thanks

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    May 16, 2016 @ 09:43
    Jan Skovgaard
    100

    Hi Tim

    Yes that is possible.

    Depending on what makes sense in order for storing the values you can choose to either save them in an array or simply as an object. Since it sounds like you're going to only have 2 values I would probably go with saving them as an object.

    So you can have something like

    $scope.model.value.value1 and $scope.model.value.value2.

    If you're using dynamic razor you can access the values by writing something like @CurrentPage.Yourpropertyaliasreferencingtheproperyvalueeditor.value1 - But please notice that this will need to reference the alias you give the property that references your property editor.

    If you prefer using strongly typed then you will ned to create a property value converter so you can access it like @Model.Content.Yourpropertyaliasreferencingtheproperyvalueeditor.value1 or simply @Model.Yourpropertyaliasreferencingtheproperyvalueeditor.value1 depending on what your razor view is inheriting from.

    In order to get going with creating custom property editors I think you should consider reading through this nice tutorial on how to create one https://our.umbraco.org/documentation/Tutorials/Creating-a-Property-Editor/ and also https://github.com/umbraco/AngularWorkbook is really useful.

    If you find out that you need access to some API methods some of them are currently documented here http://umbraco.github.io/Belle/#/api - Don't know if they will be moved to our at some point too. But I guess that would make sense.

    In regards to creating property value converters then you can learn more about them by having a look of these resources

    I myself is still struggling with this concept - But that has to do with the syntax and the fact that I'm primarly a frontend developer...But it is nice to be able to write them by yourself I find. But currently I always end up asking for some help doing it :)

    I hope this helps! :)

    /Jan

  • Tim C 161 posts 528 karma points
    May 16, 2016 @ 09:45
    Tim C
    0

    Jan

    Can't thank you enough - lots for me to look and study!

    Thanks again

Please Sign in or register to post replies

Write your reply to:

Draft