Is there a way to run some JS code for a custom validation rule & message? I see the “validation type” can be scripted, but it seems to expect one of the existing validation types to be specified (i.e. regex). I want to run a block of code for validation and return true/false. Separately, I want to provide a specific error message if that validation returns false.
My specific use case is an async unique check on a Text Input. I want to hit an API on input to verify uniqueness, then fail validation.
Hey there @bstone! This is a great question - right now there’s no native way to do this in Retool (I’ve created separate JS queries to at least tell me if the input is valid, but there’s no way to hook it up to actually prevent invalid inputs). This is a common request and definitely something we’re thinking about building.
The issue you brought up about having to specify existing validation types is a known bug that we’ll hopefully get to soon (ideally this week).
We're currently rolling out 15+ new input components, all with support for custom validation logic! You can include a short inline rule, likely using a ternary, or point to a JS query or transformer for more complex logic.
Hey Garret! How do you make a custom validation that includes some information about the field itself? In the example here, I'm trying to say:
If the previous field's selection is the "none" option, then this field must not be blank. I can't figure out how to get information about the field itself (do I use some form of self?) into this validation without getting a circular reference error:
Ideally, I'd like something like:
{{multi_type_select.value == "none" && self.length==0 : "You must specify..." : null}}
So that in this example, since a sheet has been specified, it will pass the validation, not show an error, and be eligible for submission.
In our use case, this actually might be a more common need than the 'contrived' example above where the validation is only referencing a different component.
Alternatively, is the custom rule the wrong thing for this?