Client-side validation

  • 18 November 2005
  • 4 replies
  • 3 views

Badge +1
I have looked at the KB article, http://kb.k2workflow.com/Articles/KB000008.aspx, but it does not answer the question I have. Can I use .NET client-side validators like required field, custom, etc. validators on SmartForms? If so, what I do I have to do to make them work? I have tried just putting them on the page and the K2 Button has CausesValidation set to True. Any help in this matter would be appreciated. Thanks.

4 replies

Badge +9
It is known that the validators does not stop the Process Instance from starting if the validation fails, this is the reason why we recommend the use of java script as explained in http://kb.k2workflow.com/Articles/KB000008.aspx
Badge +2
Hi,

We are using validator controls for all validation on ALL our forms (plan and client pages) without any problems...

To test for a required field server side: Add a required field validator to the form, link it to the textbox you would like to test against.

Set the K2 button's CausesValidation property to True...

When you click the button, the setting will force the required field validator to fire before the code of the button click event - thus you don't need to test for anything in code. If a field is empty the validator's error message text will be displayed - the process will not start...

You can also add a summary validator control to display the errors of all validators in one list.

Note: The validator must be visible - if it's visible property is set to False, it will not fire!

Hope this helps,
Tersia
Badge +1
Required validators works on my form, it's the custom validators I'm having trouble with. Using alerts(), I can see that the javascript function is being called and returning the correct value (args.IsValid = fase), but the form still submits. To reproduce this, create a new SmartForm, place a DDL on the form along with a custom validator and a validation summary. The form will still submit even with CausesValidation = True on the submit button.
Badge +1
Hey guys, you might consider using the K2ROM if you need page validation. I have a SmartForm where my aspx page has RequiredField Validators but I'm creating the process instance and setting datafield values through my own button click handler. If your forms are going to be used by users viewing through Firefox (rather than IE), the built in .NET validators will not fire properly. You need to have a check within your button click event handler such as

if (Page.IsValid == true)
{
//Do some stuff
}
else
{
//Don't do the stuff
}

If your users are all using IE, then setting the CausesValidation property to true should do the trick for you (assuming RequiredField and RegularExpression validators only).

Reply