Copied to clipboard

Flag this post as spam?

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


  • Tim Watts 90 posts 394 karma points
    Mar 11, 2015 @ 09:46
    Tim Watts
    0

    Set hidden field value to property from parent document

    Hi,

    I have a Contour form on which I'd like to include a property from a document which is not the one which the form will be placed on, is this possible?

    To give an example, I understand I can use [#PersonName] to get the current person, but how could I get something along the lines of [#Parent.CompanyName].  What I actually need is something more along the lines of Parent.Parent.Parent.CompanyName.

    I've seen reference to using a $ prefix for a 'recursive page value' but I'm afraid that I'm not sure what is meant by this.

    Regards,

    Tim

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Mar 11, 2015 @ 14:57
    Ismail Mayat
    0

    Tim,

    See https://our.umbraco.org/documentation/Reference/Templating/Macros/ thats for getting macro parameters and $ is recursive, it may work so try [$CompanyName]

    Not tried it myself!

    Regards

    Ismail

  • Tim Watts 90 posts 394 karma points
    Mar 11, 2015 @ 15:07
    Tim Watts
    0

    Hi Ismail,

    Thanks for the reply.  [$CompanyName] doesn't work, I'd tried that before posting.

    In the link you posted it says that the $ is for "any adjacent node of currently executed node".  That sounds like a sibling to me, not a parent.

    Also to complicate things even more I need a property of the great-grandparent!

    Any more ideas?

    Tim

     

  • Ismail Mayat 4511 posts 10062 karma points MVP 2x admin c-trib
    Mar 11, 2015 @ 15:29
    Ismail Mayat
    0

    Tim,

    Not sure about contour but $whatever will recurse until it finds a value so if parent and grandparent do not have value but great grandparent does then it will get that value.  Do your parents / grand parents have values? If not then may be it does not work for contour, if not then you may need to create your own field which can do the traversal and set the value.

    Regards

    Ismail

  • Tim Watts 90 posts 394 karma points
    Mar 11, 2015 @ 16:40
    Tim Watts
    100

    Hi Ismail,

    The $ doesn't seem to work fully in Contour.  I had a property with the same name in parent and child, the Contour form is on the child.  When referring to it with a $ I successfully got the value from the child element.  When renaming the property on the child element so that it effectively no longer existed and it would get the value from the parent, the value of the field became the literal "[$propertyName]"

    For anyone else who has this issue in future I eventually sorted it by using custom mark-up as explained here: https://our.umbraco.org/projects/umbraco-pro/contour/documentation/Developer/Custom-Markup/

    I created a file ~\umbraco\plugins\umbracoContour\Views\Forms\85514c04-e188-43d0-9246-98b34069750c\CompanyName.cshtml.  Where the GUID is that for the specific Contour form I was having issues with, and CompanyName is the field name.

    @using Umbraco.Web
    @model Umbraco.Forms.Mvc.Models.FieldViewModel
    @{
        var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
        var companyName = umbracoHelper.AssignedContentItem.Parent.Parent.Parent.Name;
    }
    
    <input type="hidden" name="@Model.Name" id="@Model.Id" class="hidden" value="@companyName" />

    This will override the markup for any field of the given name on the given Contour form, outputting a hidden field with the value derived from the object model.

    Tim

Please Sign in or register to post replies

Write your reply to:

Draft