Validate inputs
Validators check whether the value falls in the expected range, and provide visual cue if it does not. To add a validator to a parameter, provide a comma-separated list of functions that will be invoked each time a value is changed. A null indicates that the value is valid, anything else indicates an error which gets shown to the user.
A validator is a function that accepts one parameter of any type and returns a string. Choice providers are applicable only to string parameters.
- Result
- Register validators
- Use valdiators
Run this code once
grok.functions.register({
signature: 'List<String> jsVal1(int input)',
run: (input) => input < 11 ? null : "Error val1" });
grok.functions.register({
signature: 'List<String> jsVal2(int input)',
run: (input) => input > 9 ? null : "Error val2" });
https://public.datagrok.ai/scripts
#name: Numbers
#language: python title="Use registered validators"
#input: int count1 {validators: ["jsval1", "jsval2"]} [Number of cells in table]
#input: int count2 {validators: ["jsval1"]} [Number of cells in table]
#input: int count3 {validators: ["jsval2"]} [Number of cells in table]