Always Getting Form.Valid = True 

Always Getting Form.Valid = True 

  

Hi,

I have form with multiple input fields and ajax submit button with Client and server validation.

I have put custom validation on onchange of one input field its working fine.

in custom validation i am assigning input.Valid=False and when i click on button its always set input.valid=True and Form.Valid = True.

What i have done wrong ?

Thanks & Regards

DM Singh

Nothing.

It is working as expected (I think).
The Client & Server validation will perform the validation of missing values and or wrong data types and if nothing is wrong, will set the Form.Valid property to true.
If you need to perform "extra validation", you should do this in the server action, before the verification of the Form.Valid.

Cheers,

Eduardo Jauch

Hi Eduardo,

So we cant write custom validation on input onchange ?

For what I know, yes, you can, but only to alert the user at that moment.
Because every time you submit/ajax submit, the automatic validation will be executed and any input that pass the two verification will have its Valid properties set to True.

What type of validation do you need? For example if you have an imput and you want to ensure that user only type numeric, you can use javascript

Joao Soares wrote:

What type of validation do you need? For example if you have an imput and you want to ensure that user only type numeric, you can use javascript

In this case, you can set the input type to be numeric and it will accept only numbers.

I think the question here is more conceptual.
The only reason to perform a validation in the client side is to prevent the user to do an action while he does not fix any error he is creating.

In this case, for example, to enable or disable a button, etc.

Than, you can perform a validation in the OnChange and if the validation didn't pass, you don't enable the action (button, other input fields, etc).

If this is not the case, the standard approach is to let the user define its inputs and than, server side, do the custom validations and than warn the user case any input is not valid.

Cheers,

Eduardo Jauch


You right, i thought he was trying to prevent user to insert some wrong imput. Numeric was only an example, you may have other types of validation. By the way, if you want only numbers you can block "e" and "-" on type numeric?

Hi João.

That I know, not directly in the input. "-" and "e" are valid "numeric" characters.

I think you can use masks components or JavaScript directly to do it, but other than the mask (I used one from Forge), that gave me some funny side effects, I never did it myself.