Dynamically Bind Validation Value & Message


#1

Hi.
I have a form which contains a select & text input in a row. The children of this row is being repeated using server connect. And, based on the value in each row of server connect, text input or select get shown in the UI.
So a form with dynamic number and type of elements. This works great.

Now, I need to bind a custom message for required validation. I can set whether the field is required or not using dynamic attributes, but I don’t see dynamic options for validation rules.
I tried setting value for required as dmx-bind:data-msg-required="validation_message" (where validation_message is a field), but its not working correctly.
All messages are shown under first row always. And are overlapped from last to first. So only last message is visible.

Also, I need to set the regex pattern validation’s value dynamically. I can do it with dmx-bind:data-rule-pattern="validation", but again, the message is not working.

Is using code behind the best option for applying dynamic validation constraints? And how to set dynamic validation messages?


#2

@wappler_ambassadors Any thoughts on how to apply validations dynamically?


#3

Have you a link so i can see it happening?


#4

I worked on it a bit and found some bugs in my code. Have fixed them. So the pattern rule and message is working now.

The issue I think is that because the rows are dynamic but still inside a single form, they keep on getting validated.

Messaging a link to you.


#5

Sounds highly likely that is the issue


#6

Solved it. Very dumb issue on my part.

I bound dynamic validations for all elements in the repeated form row. But, only one element is visible and in-use per row.
So I should have DISABLED & HIDDEN the other elements. I just did the hiding part.
So the validation errors shown were from the hidden form elements. :sweat:
Thank you for your time @Hyperbytes .