I need to create a validation part consists of multiple input fields which has to do custom validation of different patterns to be validated at once.
For example
and so on with multiple patterns and multiple fields.
All these fields will be in the same form and screen and I need to validate all at once when the form is submitted.
How to create a centralized and Re-useable validation logic for multiple patterns?
For Eg : I need to have a function which validates Pattern 1 alone.
Whenever i pass inputs of UserName ,SiteName which has pattern1 validation it should accept and validate.
The same goes with other patterns also..
I want to keep it centralized and Re-usable in a way that it should be independent of screens and modules.
Eg:
In screen 2
I have a form which has only username(pattern1) and SerialNumber (pattern2) and submit button.
It should be able to take those inputs and validate the same.
Thanks for your time.
Hi @Vijay Raj ,
What parts of patternX should be reuseable ?
Dorine
Hi Dorine
All the 3.
If I pass username to pattern1..,it should validate the input and return true if the input is valid and return false if the input is invalid.
The same function should also be available to validate Screen Name also..since it is of the same pattern.
Thanks
Vijay
Yes, but you say 'return false', that only covers the first bullet point.
That's the easy part, just make a client function with input of value and output of boolean. I don't see where you have a difficulty with this.
The interesting and harder part to make reuseable, is what you do after that, for example setting the properties of the input.
You would have to pass the widget id into the action, and use the outsystems javascript api to access the valid properties on it.
Hi.
I assume you have the correct architecture of your widgets.
I see it like this:
you have several widgets where you use your patterns. These widgets are collected in a, say, parent widget (wrapper widget), and then, finally, you have this wrapper widget on your screen.
So, you want to validate all the things you have on your screen.
Let me suggest the following:
Let's say you have 3 widgets with different patterns.
Let's say you have a parent wrapper widget where you place your 3 widgets.
Create set of structures: Widget1_Fields, Widget2_Fields, Widget3_Fields. They are basically a form files to validate. Each widget should trigger event on every change and pass its structure to parent wrapper.
Parent wrapper has structure with all these structures: ParentStructureWrapper {Widget1_Fields, Widget2_Fields, Widget3_Fields}. When parent catch an event from any of your widget, it updates corresponding structure in ParentStructureWrapper.
Create a validation action that takes ParentStructureWrapper as an input argument. In this case, you can validate your structure at any point of time, even before submit button is pressed, but on each change from your child widgets.
Hop this helps.
Hi Dmitrii I've started your approach and tried to do what you've mentioned.
I've created a form with mutliple patterns and created 3 structures as you said..They are Patter1Fields , Pattern2 and Pattern 3 Fields..All these Patterns are also inside a parent wrapper.
I'm struggling with binding the local variable to the corresponding structure and how to pass the parent structure and where to write the logic.
I've enclosed the OML file for your reference.Kindly help me on this
hi Vijay Raj,
I am adding an oml. you can check in it. there is a screen action i have created associated with button if you send true value it will validate
or if you will pass false then it will validate
go through this oml file and let me know if it works or not.
Thanks #outsystems
Prince
Hello Prince
Thanks for your time and response
But whenever i try to open an application which has Javascript which has a function and accepts parameter., I'm getting this issue
I've googled this and found that this will happen when browser cache is full.,I've cleared it fully and i also saw the error log in service centre and found that the Javascript function is not getting initialized.
So i couldn't see the result of your OML file as well.
Kindly help me on how to solve this issue.
Thank you
Hi Vijay Raj,
i tried on my personal environvent. i am getting no error. may be you haven't refreshed the dependecy.
here is the link of the operation Click Here
Hello PrinceThanks for your reply and time.
Inspired from your solution..I've tried this method.
Where the client action screen1 validator will pass the arguments collected from screen 1 to the respective pattern validator client actions.
But I'm stucked in rightly passing the parameters.
I've enclosed the OML file for your reference.
Kindly help me on this.
Thanks,