Adding custom validation in XForm

Vote:
 

I want to add to validation on Age [RequiredFieldValidation and RegularExpressionValidator] which is in XForm.

If I add   <asp:ValidationSummary ID="ValidationSummary1" ValidationGroup="XForm" DisplayMode="BulletList" ShowSummary="true" EnableClientScript="true" runat="server" /> in the form in which XForm is loading it shows only one ErrorMessage for all validations.

You haven't specified all required fields

You haven't specified all required fields

You haven't specified all required fields

I also tried adding custom validation in global.asax.cs

 if (pg.CurrentPage.PageTypeName.Trim().ToLower() == "formname")
{
foreach (Control control in formControl.Controls)
{
if (control is BaseValidator)
((BaseValidator)control).ErrorMessage = LanguageManager.Instance.TranslateFallback("/xform/" + ((BaseValidator)control).ControlToValidate.Replace("_", "").ToLower().Trim(), "");

}
}

   but the problem is that it also show only one custom errormessage. But if i remove this code and keep the validation summary on the aspx page then after showing the errormessage "" it does show the second numeric message.

 

Any idea how can i add the custom errormessage and 2 validation.

#49021
Mar 01, 2011 5:37
Vote:
 

What you'd need to do is hook the ControlCreated event of the XFormControl, then iterate through the controls collection.  When you find an IValidator control, you need to set a custom message in the ErrorMessage property.

#49129
Mar 05, 2011 20:19
Vote:
 

See http://www.frederikvig.com/2010/11/semantic-markup-with-episerver-xforms/ for an example.

#49131
Mar 06, 2011 22:44
Vote:
 

Thanks, IValidator is adding the custom error message.

But I am trying to display the error message from my xml.

 <email>
          <caption>E-mail address</caption>
          <inlineerrormessage>Not a valid e-mail address.</inlineerrormessage>
          <summaryerrormessage>* is not a valid e-mail address.</summaryerrormessage>
        </email>

<requiredfield>
        <inlineerrormessage>This field is required</inlineerrormessage>
        <summaryerrormessage>You haven't specified all required fields</summaryerrormessage>
      </requiredfield>

this is the xml which tag which is used to display message. I am not able to figure out how summaryerrormessage of required field and for a particular datatype is set.

#49432
Mar 17, 2011 6:27