Setting Hidden Field Values to Current or parent page name
I have a form that is reused in different places throughout a site and I need to populate a hidden field value with the name of a page if the current page is of the document type x and if the document type is actually of type y then I need to populate it with the parent page name. So essentially, I want to populate it with Model.Content.AncestorOrSelf("doctypealias").Name.
Thanks David, I had thought about it but wondered if there was an out of the box solution. If not then I will go down that route so thanks for the tip.
In case it's of help to anyone else I simply inherited from the existing HiddenField type and overrode the Id, FieldTypeViewName, Name & Description values as follows:
public sealed class MyFieldType: HiddenField
{
public MyFieldType()
{
//Provider
this.Id = new Guid("F7D1D505-4B28-4EDC-937F-500DF84F77AF");
this.FieldTypeViewName = "FieldType.MyFieldType.cshtml";
this.Name = "My Field Type";
this.Description = "My field type description.";
}
}
Setting Hidden Field Values to Current or parent page name
I have a form that is reused in different places throughout a site and I need to populate a hidden field value with the name of a page if the current page is of the document type x and if the document type is actually of type y then I need to populate it with the parent page name. So essentially, I want to populate it with
Model.Content.AncestorOrSelf("doctypealias").Name
.Is this possible?
Thanks, Simon
Could you not create a custom field type and the put your code in to the razor view for for that field?
It might need to be changed like so:
If you've not done custom field types: https://our.umbraco.org/documentation/products/umbracoforms/developer/extending/adding-a-fieldtype
Thanks David, I had thought about it but wondered if there was an out of the box solution. If not then I will go down that route so thanks for the tip.
In case it's of help to anyone else I simply inherited from the existing
HiddenField
type and overrode the Id, FieldTypeViewName, Name & Description values as follows:is working on a reply...