You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/en/5-reference/5.0-form-instrument.md
+6-2Lines changed: 6 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,18 +55,22 @@ Always consider using \`group\`ing to structure sections
55
55
- Make sure your rules are correct given the paper form
56
56
- Please familiarize yourself with the possible validation rules here
57
57
- Be careful to write the most restrictive validation schema possible
58
-
- Example: likert-scale data should be .int()
58
+
- Example: likert-scale data should be `.int()`
59
+
- Example: A select from multiple string options question should be `.enum(['option1','option2', ...])` instead of `.string()`
59
60
- Remember the API data-entry is independent of the form, so the validation schema must properly restrict API entry as well
60
61
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)
61
62
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.
62
-
- For example, if your data schema is z.number().int().min(0).max(7) for every field, consider moving it into a variable, as this can reduce the cognitive load of programmers reading your form
63
+
- For example, if your data schema is `z.number().int().min(0).max(7)` for every field, consider moving it into a variable, as this can reduce the cognitive load of programmers reading your form
63
64
- On the other hand, if this is the schema for only two or three variables, creating a variable would probably increase cognitive load, rather than reducing it.
64
65
- The same applies for computed measures (i.e., define a function at the top of your file instead of copy-pasting it to every field).
65
66
7. Review common styling conventions
66
67
-https://google.github.io/styleguide/jsguide.html
67
68
8. Use [the playground](https://playground.opendatacapture.org/) to create instruments
68
69
- It is updated regularly to use the latest runtime
69
70
- It is setup with formatting, linting, and type checking by default
71
+
9. Proper use of Zod's enum type
72
+
- It is best to use Zod's enum type when the answer to a form question is a set of constant values.
73
+
- Example: A question which asks the user to choose from a selection of options should use `z.enum([option1, option2, ...])` within its zod validation schema.
0 commit comments