I am creating a customised dropdown field using the FieldTypes in a custom Theme.
FieldType.DropDownList.cshtml uses a FieldViewModel and I need to find the form that the fields are children of, because I need to look up some values using the Form-Name.
Anyone got a clue on how to get a reference to the Form from the FieldViewModel of the field?
Note that passing a new instance of the ViewDataDictionary object will overwrite any of Umbraco Forms' existing view data needed to render the field. For example, view data that has been set through calling methods like @Html.SetFormFieldWrapperClass("form-group") will be lost and the wrapper CSS class will not be applied to fields.
So instead, it's probably better to customise the existing ViewData instance and pass that. For example:
Get Form from FieldViewModel ?
I am creating a customised dropdown field using the FieldTypes in a custom Theme.
FieldType.DropDownList.cshtml uses a FieldViewModel and I need to find the form that the fields are children of, because I need to look up some values using the Form-Name.
Anyone got a clue on how to get a reference to the Form from the FieldViewModel of the field?
Ha! - answered my own question.
Fortunately, the requirement is from the Themed FieldType being called from the Themed Form, as:
So, I just needed to extend that out with a ViewDataDictionary and pass what I needed to the Themed FieldType as:
Perhaps not the most elegant of solutions, but it works for now.
Note that passing a new instance of the
ViewDataDictionary
object will overwrite any of Umbraco Forms' existing view data needed to render the field. For example, view data that has been set through calling methods like@Html.SetFormFieldWrapperClass("form-group")
will be lost and the wrapper CSS class will not be applied to fields.So instead, it's probably better to customise the existing
ViewData
instance and pass that. For example:is working on a reply...