Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

EPiServer.Forms.Samples address approach doesn't work with @Html.RequiredClientResources("Footer") & @Html.RequiredClientResources("Header")

Vote:
 

I've implemented several custom fields such as Address using the approach from EPiServer.Forms.Samples.  This custom field has multiple input boxes for street, city, post code etc.  I then set the values into a class and then convert to json. This has always worked great, until I tried adding to our layout the Client resource scripts for header and footer.    Without the client resource scripts we always had a javascript error of epi is undefined, but it never affected anything so was ok with it.  

The address model field has:

public class Address : InputElementBlockBase, IElementCustomFormatValue

When this bit runs on the submitting form:

public override object GetSubmittedValue()
        {
            var rawSubmittedData = HttpContext.Current.Request.Form;

            string[] addressComponents = rawSubmittedData.GetValues(this.Content.GetElementName());

it only ever has 1 component which is the first input box.

When I run the same code without the client resource header/footer scripts, the code will have my 7 components I am expecting.  Is there a change I need to do to make it work with the client resource scripts?  

#197545
Edited, Oct 05, 2018 16:36
Vote:
 

For custom element you need mark it as: 

class="Form__Element Form__CustomElement FormAddressElement

Then you need overide methods to get and bind its value (since it may contains multiple field). Please see the sample here: https://github.com/episerver/EPiServer.Forms.Samples/blob/master/ClientResources/ViewMode/EPiServerFormsSamples.js

Methods: bindCustomElementValue and getCustomElementValue.

#197603
Oct 09, 2018 6:22
Vote:
 

Ah I think it makes sense why it wasn't working then with client header and footer scripts on, as the code in the GetSubmittedValue was greared up to get the values with no javascript at all, but effectively worked with javascript, but just not those two scripts. 

I've done what you have recommended and have extended the episerver forms javascript and am seeing the values I want getting passed through so that's going to work. 

Many thanks! 

#197672
Oct 10, 2018 9:34
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.