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.

Hi there,

I reviewed the documentation on this and it seems like the input.valid = false should work when validating the form.  I am hoping that I am not misunderstanding the documentation.

In the example the first If sets the condition and either sets the input to input.valid = false or leaves it to the default.  It then further goes to form.valid to do the final validation.  If the form.valid does not pick up on the input.valid = false, the save will continue even when the field has 2 characters.  This has been my experience;

I check that the End date is not before the Start date in my record with a screen action, should the validation fail, I set the input.valid = false, but on the save, the form.valid simply ignored the input.valid = false and saved the record.  The workaround that I have to do now is to duplicate my validation in the save before I go to form.valid.  If there is a way to get form.valid to be a catch all for input.valid = false it would be appreciated.

Below is the example as in the documentation.

Example in a Web App

In the GoOutWeb application, a Web application for finding, reviewing, and rating places, we want the review comments to have at least 30 characters. We have a form on the home page to submit reviews. It has a Save button that calls the Save screen action.

Implement the validation as follows:

  1. Add an If element to the flow with the following condition:
    Length(ReviewForm.Record.Review.Comments) >= 30
  2. In the False branch, set the runtime properties:
    Review_Comments.Valid = False
    Review_Comments.ValidationMessage = "The minimum is 30 characters"
  3. Add an If element with the following condition:
    Form.Valid
  4. If True, continue the action flow. If False, end the action flow.
  5. Publish and test adding a review with less than 30 characters.

Hello Tjaart.

You need to remember that on submit (or ajax submit), if you defined any validation method (Client & Server or Server), the automatic validation will be performed and ANY previous Valid value set will be overwrite.

This will cause the behaviour you're seeing. You set the input.Valid = False in a screen action (OnChange?), but when you finally submit the form, this will be ignored, because if the input pass both automatic validations (data type and mandatory), the valid WILL be set to True.

In this case, you will have to repeat the test in every action you run where you pretend to use that value.

Cheers.

Hi Eduardo,

Thanks for the quick response and for clearing this up.

You're welcome, Tjaart :)

Hi


In addition to code validation, we've found using masks very helpful both for validation and for UX/UI purposes. This way your users know what they can and can't type and it saves an additional click or two in some cases. There are a couple of plugins that can help you with this such as this one for mobile or this one for web. 

I however still recomend validating the inputs on the server side, since the masks are still JS code, a clueless (or malicious) soul might have JS turned off and get around client side validation including masks.


Hope this helps!


Regards,

   Carlos López S. Jácome