r3-team / r3

REI3 - Free and open low code
https://rei3.de
MIT License
323 stars 47 forks source link

feature request: custom validate function #31

Closed gizocz closed 1 year ago

gizocz commented 1 year ago

Hello, I need an custom form filead validation JavaScript function.

It could be, for example, done by 1) adding an "Validate with function" item in the Form Filed Settings. The function would return true/false. or 2) in a "Function on value change", adding a new option "write error message" in Function -> Placeholdes Settings -> Form data fields.

I vote for (2), because it can also set the error message (Althought, the case (1) can also set the error message e.g. throwing an error).

It would also be great if the Form State Condition had an "fileds is invalid" option. So, for example, an button would be disabled if a field is invalid.

r3-gabriel commented 1 year ago

Hello,

Option 1. would be straightforward: If the function checking the field value returns 'false', the field would be marked 'invalid' and a generic 'field input is invalid' message would be shown.

Option 2. would also work but the interaction between the regular field validation (required input, valid input type, etc.) and the event-driven 'function on value change' might be tricky. It would be more flexible however. In any case, you would have to be able to remove the error message as well if the input changed to a valid state.

I also vote for option 2. I will add this feature request to our list for the next releases.

The idea to use the field validity as a form state condition is good - however if we go with option 2. (writing a field error message directly), we would also need to consider this case as 'field is invalid' as I see it. This means that the condition 'field is invalid' would react equally to 'regular field validity check failed' and 'custom error message was placed on field by a function'. Does this make sense to you?

r3-gabriel commented 1 year ago

Feature implemented for 3.3 release.