Trigger validation without submitting form

Vote:
 

Hi,

I have a use case where I want to trigger the standard Episerver Forms validators of an Episerver form, without submitting it.

Preferrably, I'd like to do this client side, using javascript.

What is the best way of achieving this?

Right now I'm able to mimic the standard behaviour by using the 'epi.EPiServer.Forms.Validation' and 'epi.EPiServer.Forms.Utils', but I'm looking for a less hackish way of doing this, if that is possible.

A quick example of how I would validate an element with my current solution:

var formInfo = epi.EPiServer.Forms['ce9d363a-b826-480f-a061-96fd2b0ca017']
var validators = epi.EPiServer.Forms.Validation.getElementValidators(formInfo.ValidationInfo, '13e66f49-4241-4f90-81e4-df253bc898ef')
var validated = epi.EPiServer.Forms.Validation.validateFormValue('__field_46111', value, validators)

Then I'd implement some functionality to toggle classes, and displaying any validation error messages from the 'validated' data.

Any suggestions or ideas on how to do this in a cleaner way, are appreciated.

Thank you!

Best regards,
Tobias

#229420
Oct 14, 2020 9:54
* 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.