Skip to content

Commit 8005339

Browse files
committed
refactor: put best practice of string option to enum as restrictive validation example instead
1 parent dd13d14 commit 8005339

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

docs/en/5-reference/5.0-form-instrument.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Always consider using \`group\`ing to structure sections
5656
- Please familiarize yourself with the possible validation rules here
5757
- Be careful to write the most restrictive validation schema possible
5858
- Example: likert-scale data should be .int()
59+
- Example: A select from multiple string options question should be .enum(['option1','option2', ...]) instead of .string()
5960
- Remember the API data-entry is independent of the form, so the validation schema must properly restrict API entry as well
6061
5. Please make sure to format your code whenever possible, as this can prevent annoying issues with missing brackets. In the playground, you can do this with (Alt + F)
6162
6. If you find yourself repeating code frequently, consider extracting the logic into shared variables. The guiding principle of this should be to maximize readability.
@@ -67,7 +68,6 @@ Always consider using \`group\`ing to structure sections
6768
8. Use [the playground](https://playground.opendatacapture.org/) to create instruments
6869
- It is updated regularly to use the latest runtime
6970
- It is setup with formatting, linting, and type checking by default
70-
9. Whenever a form field of kind 'string', and of variant 'select' is used, it is much better to have its schema be of type enum containing the possible options instead of type string ( i.e. z.enum(['string1', 'string2', ...]) instead of z.string() ).
7171

7272
### Example
7373

0 commit comments

Comments
 (0)