Advanced Question: How to get a list of form inputs that failed validation?


I am trying to figure out which input fields have failed validation dynamically.

I have form and a "Validate" button (Method:Ajax Submit, Validation:Server). The purpose of the Validate button is to show a popup screen with a clear list of fields that have failed validation.

I wish I could generate a Text List of input fields that have failed validation. Specifically the attribute that they represent (I always know which entity). With this list, I will display a popup to the user to clearly describe which fields have failed validation.

I am aware that I can probably use a bunch of IF conditions, but I also need this to work dynamically (since this will implemented for many forms of many fields).

The closest I got is obtaining a list of input fields that have failed validation client-side with some javascript. But I am not very comfortable extracting attribute names from weird OS input names, and I don't seem to be able to get the attribute name on dropdowns. Hopefully there is a way to do this server side.

I am open to any suggestions, thank you very much!

Hi David,

The pattern you are describing is not the OutSystems way. In OutSystems, inputs have a runtime Property "Valid" that indicates whether they have passed the validation. There's also a runtime Property "ValidationMessage", that contains the message to show. What you'd typically do, when using Server Validation (a Property of the Button or Link), is to check, for each Input Widget, whether it contains a valid value, and if not, set its Valid Property to False and set an appropriate ValidationMessage. Next, after all validations, you'd refresh the Form or Edit Record Widget, and the validation messages will be presented to the user next to the respective Input Widgets (their exact format determined by CSS).

Since you have actually set the Validation to Server, you can't "obtain a list of input fields" client-side, since you need to do the validation in the code. That's what server validation means. When you use Client & Server, then some of the Input Widgets may already have their Valid set to False, when there's e.g. a non-number in a numerical input, but you could test them 1 by 1, since even if a number is valid, you'd probably like to check its range.

Hi Kilian,

Thank you for your input on this matter. I'm aware of the runtime properties Valid and ValidationMessage, and have used it perform custom validation on my form fields.

I have set the Validation to server so that the server handles the validation, more specifically, so that the validation is performed somewhere I can intercept it. If I left the Validate button to do client-side validation as well, nothing would be sent to the server because the process would be interrupted client-side, and ideally I'd be intercepting everything server-side (so that I can set Valid=False and refresh the form with my own custom validation).

In either case, my issue remains - I cannot figure a way to dynamically get a list of inputs that have failed validation without explicitly testing each value server-side.

The only work around I have found so far is having the Validate button perform my validation and then trigger a javascript event to look at the actual form (in the DOM) and pickup all the fields that have failed validation, then encode this list as a string and pass it as a parameter to a popup. It works, but I wish I could do all of this server-side dynamically.

Hopefully that clears up my issue. Any feedback is greatly appreciated.