November Happy Hour will be moved to Thursday December 5th.

EPiServerForms.js doesn't recognize successful submission response

Vote:
 

EPiServerForms.js expects an ajax response in camelCase, but JsonResult renders the response in PascalCase. Therefore, when using the JS submission mode for forms, the client-side script misinterprets a true value for isSuccessful in the response as a failure. Though the form has been submitted successfully and the data saved and visible on the list of submissions, the user cannot tell that their submssion succeeded because no message is displayed.

Configuring JsonOptions in Startup.cs seems to fix this:

 services.Configure<JsonOptions>(o =>
{
  o.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
});

However, I'm not sure what else this might break.

#274668
Feb 28, 2022 3:55
Vote:
 

Foundation explicitly sets the JsonNamingPolicy to null so we get PascalCase.

https://github.com/episerver/Foundation/blob/5ed791d16309f34390e4c37b94836b63f27edbc7/src/Foundation/Startup.cs#L158

services.AddControllers()
  .AddJsonOptions(options =>
  {
    options.JsonSerializerOptions.PropertyNamingPolicy = null;
  });

So, perhap the source JS will need to be changed to match the case of the response that the DataSubmitController is returning on submit.

#275599
Mar 03, 2022 15:36
Vote:
 

Setting it to null means it will leave property names unchanged -- I set it like that in Foundation because without that it was CamelCasing all the property names and a lot of things weren't working correctly (just like the issue in this thread, though I hadn't tested Forms at that point). It was either update all of the possible problem spots in Foundation, or make this change -- for a new build (versus an upgrade), I don't know if I would include that.

#275910
Mar 08, 2022 15:46
Vote:
 

Thanks Daniel. That makes sense. There's no reason to change the client code if you can just set the site to produce the casing the client code expects.

I think the Forms js assets included in the package need to be changed, right? I don't know how we could set Json config only for the DataSubmitController.

#276006
Mar 09, 2022 19:38
Vote:
 

Haven't tested, but I think the latest Forms release (EPiServer.Forms 5.3.0) should lead to more expected behavior:

https://world.optimizely.com/documentation/Release-Notes/ReleaseNote/?releaseNoteId=AFORM-3114

"Fixed an issue where changing the JSON formatting options to Pascal case in Startup.cs changed the form format.  For example, if you created a form that redirected after submitting the form, it would not redirect to the selected page."

#289026
Oct 11, 2022 18:56
* 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.