Custom Validation

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).

P.S: moving this over to #feature-requests.

Any news on this? such a basic feature.

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.

(forgive the contrived example)

If you don't see the new inputs in the component list yet, check back in a few days. We should be fully rolled out sometime this week.

Check out the changelog for more details.

1 Like

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?

@MarkR You should be able to use the ID of the component where you have self in your example: spreadsheet_id_input.length === 0

Though I like the idea of this or self as a shortcut for that!

Perfect! Not sure why it was giving me that circular error before. Appreciate it!

Last question - is it possible to get the cool green checkmark that the other fields in the image have, once this condition is satisfied?