form0-core 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/README.md +63 -0
  2. package/package.json +5 -2
  3. package/src/builtins/builtin-definitions.js +320 -0
  4. package/src/builtins/choice/choicelabel.js +2 -17
  5. package/src/builtins/choice/choicelabels.js +2 -17
  6. package/src/builtins/choice/choicevalue.js +2 -20
  7. package/src/builtins/choice/choicevalues.js +2 -17
  8. package/src/builtins/choice/hasother.js +2 -20
  9. package/src/builtins/choice/other.js +2 -20
  10. package/src/builtins/control/eval.js +78 -31
  11. package/src/builtins/control/setresult.js +29 -17
  12. package/src/builtins/date/dateadd.js +24 -0
  13. package/src/builtins/date/days.js +22 -0
  14. package/src/builtins/event/control/off.js +3 -27
  15. package/src/builtins/event/control/on.js +3 -19
  16. package/src/builtins/event/event-operations-collector.js +33 -9
  17. package/src/builtins/event/field/setvalue.js +3 -32
  18. package/src/builtins/event/ui/alert.js +3 -11
  19. package/src/builtins/logical/and.js +2 -17
  20. package/src/builtins/logical/array.js +2 -35
  21. package/src/builtins/logical/count.js +2 -20
  22. package/src/builtins/logical/counta.js +2 -20
  23. package/src/builtins/logical/countblank.js +2 -20
  24. package/src/builtins/logical/if.js +2 -20
  25. package/src/builtins/logical/or.js +2 -17
  26. package/src/builtins/math/abs.js +2 -20
  27. package/src/builtins/math/ceiling.js +2 -20
  28. package/src/builtins/math/cos.js +2 -20
  29. package/src/builtins/math/round.js +2 -23
  30. package/src/builtins/math/sin.js +2 -20
  31. package/src/builtins/registry.js +23 -40
  32. package/src/builtins/schema/datanames.js +9 -20
  33. package/src/builtins/schema/form.js +2 -20
  34. package/src/builtins/string/upper.js +2 -20
  35. package/src/engine/calculation-diagnostics.js +107 -0
  36. package/src/engine/calculation.js +65 -32
  37. package/src/engine/evaluator.js +56 -18
  38. package/src/engine/event-operation-scope.js +61 -0
  39. package/src/engine/event-source.js +164 -0
  40. package/src/engine/events.js +105 -19
  41. package/src/engine/form-engine.js +61 -16
  42. package/src/engine/warning-system.js +7 -5
  43. package/src/schema/field-specs.js +2 -2
  44. package/src/security/validation.js +10 -8
  45. package/src/utilities/calculation-editor.js +42 -6
  46. package/src/utilities/date-utils.js +72 -0
  47. package/src/builtins/docs/choice/choicelabel.mdx +0 -110
  48. package/src/builtins/docs/choice/choicelabels.mdx +0 -230
  49. package/src/builtins/docs/choice/choicevalue.mdx +0 -109
  50. package/src/builtins/docs/choice/choicevalues.mdx +0 -196
  51. package/src/builtins/docs/choice/hasother.mdx +0 -133
  52. package/src/builtins/docs/choice/other.mdx +0 -150
  53. package/src/builtins/docs/control/setresult.mdx +0 -203
  54. package/src/builtins/docs/event/field/setvalue.mdx +0 -239
  55. package/src/builtins/docs/index.mdx +0 -234
  56. package/src/builtins/docs/logical/and.mdx +0 -141
  57. package/src/builtins/docs/logical/if.mdx +0 -94
  58. package/src/builtins/docs/logical/or.mdx +0 -191
  59. package/src/builtins/docs/overview.mdx +0 -258
@@ -1,230 +0,0 @@
1
- ---
2
- title: "CHOICELABELS Builtin"
3
- description: "Retrieve all selected choice labels from MultiChoiceField"
4
- category: "choice"
5
- tags: ["choice", "multichoice", "labels", "array"]
6
- ---
7
-
8
- # CHOICELABELS Function
9
-
10
- The `CHOICELABELS` builtin retrieves an array of all selected choice field labels from a MultiChoiceField, preserving the type of each label. Returns an empty array if no selections are made.
11
-
12
- ## Syntax
13
-
14
- ```javascript
15
- CHOICELABELS(multiChoiceField)
16
- ```
17
-
18
- ## Parameters
19
-
20
- | Parameter | Type | Description |
21
- |-----------|------|-------------|
22
- | `multiChoiceField` | `Object` | The multi choice field object with choices and other arrays |
23
-
24
- ## Return Value
25
-
26
- Returns an array of selected choice labels with preserved types. Returns an empty array if no selections are made.
27
-
28
- ## Examples
29
-
30
- ### Basic Usage
31
-
32
- ```javascript
33
- // Get all selected color labels
34
- CHOICELABELS($colors)
35
- ```
36
-
37
- ### Display Logic
38
-
39
- ```javascript
40
- // Display selected labels in a sentence
41
- "Selected colors: " + CHOICELABELS($colors).join(", ")
42
-
43
- // Show count with labels
44
- CHOICELABELS($skills).length + " skills selected: " + CHOICELABELS($skills).join(" • ")
45
- ```
46
-
47
- ### Array Operations
48
-
49
- ```javascript
50
- // Check if specific label is selected
51
- CHOICELABELS($categories).includes("Technology")
52
-
53
- // Get number of selected items
54
- CHOICELABELS($preferences).length
55
-
56
- // Join labels with custom separator
57
- CHOICELABELS($tags).join(" | ")
58
- ```
59
-
60
- ### Conditional Logic
61
-
62
- ```javascript
63
- // Check if multiple items are selected
64
- CHOICELABELS($options).length > 1
65
-
66
- // Check if specific label is selected
67
- CHOICELABELS($features).includes("Premium Plan")
68
- ```
69
-
70
- ### Validation
71
-
72
- ```javascript
73
- // Ensure at least 2 items are selected
74
- CHOICELABELS($skills).length >= 2
75
-
76
- // Validate maximum selections
77
- CHOICELABELS($interests).length <= 3
78
- ```
79
-
80
- ### User-Friendly Display
81
-
82
- ```javascript
83
- // Create user-friendly summaries
84
- "Your interests: " + CHOICELABELS($interests).join(", ")
85
-
86
- // Display with proper grammar
87
- IF(CHOICELABELS($items).length === 1,
88
- "You selected: " + CHOICELABELS($items)[0],
89
- "You selected: " + CHOICELABELS($items).join(", "))
90
- ```
91
-
92
- ## Common Use Cases
93
-
94
- - **User interface**: Display human-readable labels to users
95
- - **Form summaries**: Show selected options in confirmation screens
96
- - **Validation**: Check selection counts and specific labels
97
- - **Reports**: Generate user-friendly reports with readable labels
98
- - **Email templates**: Include selected options in notifications
99
-
100
- ## Best Practices
101
-
102
- 1. **User-friendly display**: Use labels for showing selections to users (more readable than values)
103
- 2. **Type preservation**: The function preserves the original type of each label (string, number, etc.)
104
- 3. **Empty array handling**: Always check for empty arrays when no selections are made
105
- 4. **Array methods**: Use JavaScript array methods for processing (includes, join, filter, etc.)
106
- 5. **Internationalization**: Labels can be localized while values remain consistent
107
-
108
- ## Related Functions
109
-
110
- - [`CHOICEVALUES`](./choicevalues.mdx) - Get all selected choice values (MultiChoiceField)
111
- - [`CHOICEVALUE`](./choicevalue.mdx) - Get the selected choice value (SingleChoiceField)
112
- - [`CHOICELABEL`](./choicelabel.mdx) - Get the selected choice label (SingleChoiceField)
113
- - [`HASOTHER`](./hasother.mdx) - Check if other option is selected
114
- - [`OTHER`](./other.mdx) - Get the other option value
115
-
116
- ## Examples by Use Case
117
-
118
- ### Form Summaries
119
-
120
- ```javascript
121
- // Create a comprehensive form summary
122
- "Selected preferences: " + CHOICELABELS($preferences).join(", ")
123
-
124
- // Show selection count with labels
125
- "You have selected " + CHOICELABELS($courses).length + " courses: " + CHOICELABELS($courses).join(", ")
126
- ```
127
-
128
- ### Conditional Display
129
-
130
- ```javascript
131
- // Show different content based on selections
132
- IF(CHOICELABELS($membership).includes("Premium"), "Premium features available", "Upgrade to access premium features")
133
-
134
- // Display based on selection count
135
- IF(CHOICELABELS($skills).length >= 3, "Expert level detected", "Beginner level")
136
- ```
137
-
138
- ### Email Templates
139
-
140
- ```javascript
141
- // Generate email content with selected options
142
- "Dear user, you have selected the following services: " + CHOICELABELS($services).join(", ")
143
-
144
- // Confirmation messages
145
- "Your subscription includes: " + CHOICELABELS($subscription_features).join(" • ")
146
- ```
147
-
148
- ### Validation Messages
149
-
150
- ```javascript
151
- // User-friendly validation messages
152
- IF(CHOICELABELS($required_skills).length < 2,
153
- "Please select at least 2 skills",
154
- "Skills selected: " + CHOICELABELS($required_skills).join(", "))
155
- ```
156
-
157
- ### Report Generation
158
-
159
- ```javascript
160
- // Generate user-friendly reports
161
- "Popular choices: " + CHOICELABELS($popular_items).join(", ")
162
-
163
- // Statistical summaries
164
- CHOICELABELS($survey_responses).length + " responses recorded"
165
- ```
166
-
167
- ### Dynamic Content
168
-
169
- ```javascript
170
- // Show content based on selected labels
171
- IF(CHOICELABELS($interests).includes("Sports"), "Check out our sports section!", "")
172
-
173
- // Personalized recommendations
174
- "Based on your selection of " + CHOICELABELS($preferences).join(" and ") + ", we recommend..."
175
- ```
176
-
177
- ## Type Preservation
178
-
179
- The function automatically preserves the original type of each label:
180
-
181
- ```javascript
182
- // String labels remain strings
183
- CHOICELABELS($colors) // ["Red", "Blue", "Green"]
184
-
185
- // Numeric labels remain numbers
186
- CHOICELABELS($ratings) // [4, 5, 3]
187
-
188
- // Mixed types are preserved
189
- CHOICELABELS($mixed) // ["Text Label", 42, "Another Label"]
190
- ```
191
-
192
- ## Array Methods
193
-
194
- Use standard JavaScript array methods for processing:
195
-
196
- ```javascript
197
- // Check if array contains label
198
- CHOICELABELS($skills).includes("JavaScript")
199
-
200
- // Get array length
201
- CHOICELABELS($items).length
202
-
203
- // Join with separator
204
- CHOICELABELS($tags).join(", ")
205
-
206
- // Filter labels
207
- CHOICELABELS($categories).filter(label => label.startsWith("Tech"))
208
-
209
- // Map labels
210
- CHOICELABELS($codes).map(label => label.toUpperCase())
211
- ```
212
-
213
- ## Labels vs Values
214
-
215
- Understanding when to use labels vs values:
216
-
217
- ```javascript
218
- // Use CHOICELABELS for user display
219
- "You selected: " + CHOICELABELS($colors).join(", ") // "Red, Blue, Green"
220
-
221
- // Use CHOICEVALUES for logic/processing
222
- IF(CHOICEVALUES($colors).includes("red"), "Red color processing", "") // uses value "red"
223
- ```
224
-
225
- ## Field Type Compatibility
226
-
227
- - **MultiChoiceField**: Primary use case - returns array of selected labels
228
- - **SingleChoiceField**: Not applicable - use `CHOICELABEL()` instead
229
- - **Note**: Always returns an array, even if empty
230
- - **Localization**: Labels can be localized while maintaining consistent values
@@ -1,109 +0,0 @@
1
- ---
2
- title: "CHOICEVALUE Builtin"
3
- description: "Retrieve the selected choice field value with type preservation"
4
- category: "choice"
5
- tags: ["choice", "value", "selection"]
6
- ---
7
-
8
- # CHOICEVALUE Function
9
-
10
- The `CHOICEVALUE` builtin retrieves the currently selected choice field value, preserving the original data type. If the value is a number, it preserves the number type; otherwise, it returns a string.
11
-
12
- ## Syntax
13
-
14
- ```javascript
15
- CHOICEVALUE(choiceField)
16
- ```
17
-
18
- ## Parameters
19
-
20
- | Parameter | Type | Description |
21
- |-----------|------|-------------|
22
- | `choiceField` | `Object` | The choice field object with choice and other arrays |
23
-
24
- ## Return Value
25
-
26
- Returns the selected choice value with preserved type, or `null` if no selection is made.
27
-
28
- ## Examples
29
-
30
- ### Basic Usage
31
-
32
- ```javascript
33
- // Get the selected city value
34
- CHOICEVALUE($city)
35
- ```
36
-
37
- ### Conditional Logic
38
-
39
- ```javascript
40
- // Use in conditional expressions
41
- IF(CHOICEVALUE($city) === "bogota", "Welcome to Bogotá!", "Welcome!")
42
- ```
43
-
44
- ### Calculations
45
-
46
- ```javascript
47
- // Use numeric choice values in calculations
48
- CHOICEVALUE($priority) * 10
49
- ```
50
-
51
- ### Comparison Operations
52
-
53
- ```javascript
54
- // Compare with other values
55
- CHOICEVALUE($status) === "active"
56
- ```
57
-
58
- ## Type Preservation
59
-
60
- The function preserves the original data type of the choice value:
61
-
62
- ```javascript
63
- // If choice value is "42" (string), returns 42 (number)
64
- // If choice value is "hello" (string), returns "hello" (string)
65
- // If choice value is 3.14 (number), returns 3.14 (number)
66
- ```
67
-
68
-
69
-
70
- ## Common Use Cases
71
-
72
- - **Conditional logic**: Make decisions based on selected values
73
- - **Calculations**: Use numeric choice values in mathematical operations
74
- - **Data processing**: Extract choice values for further processing
75
- - **Validation**: Check if specific values are selected
76
-
77
- ## Best Practices
78
-
79
- 1. **Handle null values**: Always check for null when no selection is made
80
- 2. **Type awareness**: Be aware of type preservation when using in calculations
81
-
82
- ## Related Functions
83
-
84
- - [`CHOICELABEL`](./choicelabel.mdx) - Get the selected choice label
85
- - [`HASOTHER`](./hasother.mdx) - Check if other option is selected
86
- - [`OTHER`](./other.mdx) - Get the other option value
87
-
88
- ## Examples by Use Case
89
-
90
- ### E-commerce Priority
91
-
92
- ```javascript
93
- // Calculate priority score based on selected priority level
94
- CHOICEVALUE($priority) * 100
95
- ```
96
-
97
- ### Status-Based Logic
98
-
99
- ```javascript
100
- // Show different messages based on status
101
- IF(CHOICEVALUE($status) === "premium", "Premium features enabled", "Standard features")
102
- ```
103
-
104
- ### Numeric Calculations
105
-
106
- ```javascript
107
- // Use numeric choice values in calculations
108
- CHOICEVALUE($quantity) * CHOICEVALUE($price)
109
- ```
@@ -1,196 +0,0 @@
1
- ---
2
- title: "CHOICEVALUES Builtin"
3
- description: "Retrieve all selected choice values from MultiChoiceField"
4
- category: "choice"
5
- tags: ["choice", "multichoice", "values", "array"]
6
- ---
7
-
8
- # CHOICEVALUES Function
9
-
10
- The `CHOICEVALUES` builtin retrieves an array of all selected choice field values from a MultiChoiceField, preserving the type of each value. Returns an empty array if no selections are made.
11
-
12
- ## Syntax
13
-
14
- ```javascript
15
- CHOICEVALUES(multiChoiceField)
16
- ```
17
-
18
- ## Parameters
19
-
20
- | Parameter | Type | Description |
21
- |-----------|------|-------------|
22
- | `multiChoiceField` | `Object` | The multi choice field object with choices and other arrays |
23
-
24
- ## Return Value
25
-
26
- Returns an array of selected choice values with preserved types. Returns an empty array if no selections are made.
27
-
28
- ## Examples
29
-
30
- ### Basic Usage
31
-
32
- ```javascript
33
- // Get all selected color values
34
- CHOICEVALUES($colors)
35
- ```
36
-
37
- ### Array Operations
38
-
39
- ```javascript
40
- // Check if "red" is selected
41
- CHOICEVALUES($colors).includes("red")
42
-
43
- // Get number of selected items
44
- CHOICEVALUES($skills).length
45
-
46
- // Join values with separator
47
- CHOICEVALUES($categories).join(", ")
48
- ```
49
-
50
- ### Conditional Logic
51
-
52
- ```javascript
53
- // Check if multiple items are selected
54
- CHOICEVALUES($preferences).length > 1
55
-
56
- // Check if specific value is selected
57
- CHOICEVALUES($features).includes("premium")
58
- ```
59
-
60
- ### Validation
61
-
62
- ```javascript
63
- // Ensure at least 2 items are selected
64
- CHOICEVALUES($skills).length >= 2
65
-
66
- // Validate maximum selections
67
- CHOICEVALUES($options).length <= 5
68
- ```
69
-
70
- ### Data Processing
71
-
72
- ```javascript
73
- // Process selected values
74
- "Selected: " + CHOICEVALUES($items).join(" | ")
75
-
76
- // Count selections
77
- "You selected " + CHOICEVALUES($choices).length + " items"
78
- ```
79
-
80
- ## Common Use Cases
81
-
82
- - **Data extraction**: Get all selected values for processing
83
- - **Validation**: Check selection counts and specific values
84
- - **Display logic**: Show selected values in custom format
85
- - **Conditional behavior**: Make decisions based on selected values
86
- - **Form calculations**: Use selected values in calculations
87
-
88
- ## Best Practices
89
-
90
- 1. **Type preservation**: The function preserves the original type of each value (string, number, etc.)
91
- 2. **Empty array handling**: Always check for empty arrays when no selections are made
92
- 3. **Array methods**: Use JavaScript array methods for processing (includes, join, filter, etc.)
93
- 4. **Performance**: Efficient for checking multiple values at once
94
- 5. **Validation**: Use for enforcing selection limits and requirements
95
-
96
- ## Related Functions
97
-
98
- - [`CHOICELABELS`](./choicelabels.mdx) - Get all selected choice labels (MultiChoiceField)
99
- - [`CHOICEVALUE`](./choicevalue.mdx) - Get the selected choice value (SingleChoiceField)
100
- - [`CHOICELABEL`](./choicelabel.mdx) - Get the selected choice label (SingleChoiceField)
101
- - [`HASOTHER`](./hasother.mdx) - Check if other option is selected
102
- - [`OTHER`](./other.mdx) - Get the other option value
103
-
104
- ## Examples by Use Case
105
-
106
- ### Selection Validation
107
-
108
- ```javascript
109
- // Require at least 2 skills
110
- CHOICEVALUES($skills).length >= 2
111
-
112
- // Ensure premium feature is selected if advanced is selected
113
- IF(CHOICEVALUES($features).includes("advanced"), CHOICEVALUES($features).includes("premium"), true)
114
- ```
115
-
116
- ### Display Logic
117
-
118
- ```javascript
119
- // Show selected values in a custom format
120
- "Your selections: " + CHOICEVALUES($preferences).join(" • ")
121
-
122
- // Display count with proper pluralization
123
- CHOICEVALUES($items).length + (CHOICEVALUES($items).length === 1 ? " item" : " items") + " selected"
124
- ```
125
-
126
- ### Conditional Processing
127
-
128
- ```javascript
129
- // Different logic based on selections
130
- IF(CHOICEVALUES($payment_methods).includes("credit_card"), "Credit card processing enabled", "Standard payment only")
131
-
132
- // Check for conflicting selections
133
- IF(AND(CHOICEVALUES($options).includes("basic"), CHOICEVALUES($options).includes("premium")), "Conflicting options selected", "Valid selection")
134
- ```
135
-
136
- ### Data Analysis
137
-
138
- ```javascript
139
- // Calculate total based on selected values
140
- CHOICEVALUES($services).reduce((sum, value) => sum + (value === "premium" ? 100 : 50), 0)
141
-
142
- // Filter numeric values
143
- CHOICEVALUES($quantities).filter(val => typeof val === 'number').reduce((sum, val) => sum + val, 0)
144
- ```
145
-
146
- ### Form Behavior
147
-
148
- ```javascript
149
- // Show additional fields based on selections
150
- IF(CHOICEVALUES($interests).includes("technology"), "Show tech-related questions", "")
151
-
152
- // Enable features based on selections
153
- IF(CHOICEVALUES($subscriptions).includes("pro"), "Pro features enabled", "Basic features only")
154
- ```
155
-
156
- ## Type Preservation
157
-
158
- The function automatically preserves the original type of each value:
159
-
160
- ```javascript
161
- // String values remain strings
162
- CHOICEVALUES($colors) // ["red", "blue", "green"]
163
-
164
- // Numeric values remain numbers
165
- CHOICEVALUES($ratings) // [4, 5, 3]
166
-
167
- // Mixed types are preserved
168
- CHOICEVALUES($mixed) // ["text", 42, "another"]
169
- ```
170
-
171
- ## Array Methods
172
-
173
- Use standard JavaScript array methods for processing:
174
-
175
- ```javascript
176
- // Check if array contains value
177
- CHOICEVALUES($skills).includes("javascript")
178
-
179
- // Get array length
180
- CHOICEVALUES($items).length
181
-
182
- // Join with separator
183
- CHOICEVALUES($tags).join(", ")
184
-
185
- // Filter values
186
- CHOICEVALUES($numbers).filter(n => n > 5)
187
-
188
- // Map values
189
- CHOICEVALUES($codes).map(code => code.toUpperCase())
190
- ```
191
-
192
- ## Field Type Compatibility
193
-
194
- - **MultiChoiceField**: Primary use case - returns array of selected values
195
- - **SingleChoiceField**: Not applicable - use `CHOICEVALUE()` instead
196
- - **Note**: Always returns an array, even if empty
@@ -1,133 +0,0 @@
1
- ---
2
- title: "HASOTHER Builtin"
3
- description: "Check if user entered an other option in choice field (SingleChoiceField or MultiChoiceField)"
4
- category: "choice"
5
- tags: ["choice", "other", "validation", "multichoice"]
6
- ---
7
-
8
- # HASOTHER Function
9
-
10
- The `HASOTHER` builtin checks if the user has entered an "other" option in a choice field, returning `true` if an other option is present, `false` otherwise. Works with both SingleChoiceField (single selection) and MultiChoiceField (multiple selections).
11
-
12
- ## Syntax
13
-
14
- ```javascript
15
- HASOTHER(choiceField)
16
- ```
17
-
18
- ## Parameters
19
-
20
- | Parameter | Type | Description |
21
- |-----------|------|-------------|
22
- | `choiceField` | `Object` | The choice field object (SingleChoiceField with choice array or MultiChoiceField with choices array) and other array |
23
-
24
- ## Return Value
25
-
26
- Returns `true` if user entered an other option, `false` otherwise.
27
-
28
- ## Examples
29
-
30
- ### Basic Usage - SingleChoiceField
31
-
32
- ```javascript
33
- // Check if user entered other option in single choice field
34
- HASOTHER($city)
35
- ```
36
-
37
- ### Basic Usage - MultiChoiceField
38
-
39
- ```javascript
40
- // Check if user entered other option in multi choice field
41
- HASOTHER($colors)
42
- ```
43
-
44
- ### Conditional Logic
45
-
46
- ```javascript
47
- // Show different content based on other option in single choice
48
- IF(HASOTHER($city), "Custom city: " + OTHER($city), "Selected city: " + CHOICELABEL($city))
49
-
50
- // Show different content based on other option in multi choice
51
- IF(HASOTHER($colors), "Custom color: " + OTHER($colors), "Selected colors: " + CHOICELABELS($colors).join(", "))
52
- ```
53
-
54
- ### Validation
55
-
56
- ```javascript
57
- // Require additional validation when other is selected
58
- IF(HASOTHER($category), OTHER($category).length > 0, true)
59
- ```
60
-
61
- ### Form Behavior
62
-
63
- ```javascript
64
- // Show additional fields when other is selected
65
- IF(HASOTHER($reason), "Please specify: " + OTHER($reason), "")
66
- ```
67
-
68
- ## Use Cases
69
-
70
- - **Conditional display**: Show additional fields or content when other options are selected
71
- - **Validation**: Apply different validation rules when other options are present
72
- - **Data processing**: Handle other options differently in calculations or logic
73
- - **User experience**: Provide context-aware feedback based on other selections
74
- - **Multi-choice support**: Works seamlessly with both single and multiple choice fields
75
-
76
- ## Best Practices
77
-
78
- 1. **Combine with OTHER**: Use together with `OTHER()` function to get the actual other value
79
- 2. **Validation**: Always validate other inputs when `HASOTHER` returns true
80
- 3. **User feedback**: Provide clear feedback when other options are selected
81
- 4. **Field dependencies**: Use to show/hide related fields
82
- 5. **Multi-choice compatibility**: Works with both SingleChoiceField and MultiChoiceField
83
-
84
- ## Related Functions
85
-
86
- - [`OTHER`](./other.mdx) - Get the other option value
87
- - [`CHOICEVALUE`](./choicevalue.mdx) - Get the selected choice value (SingleChoiceField)
88
- - [`CHOICELABEL`](./choicelabel.mdx) - Get the selected choice label (SingleChoiceField)
89
- - [`CHOICEVALUES`](./choicevalues.mdx) - Get all selected choice values (MultiChoiceField)
90
- - [`CHOICELABELS`](./choicelabels.mdx) - Get all selected choice labels (MultiChoiceField)
91
-
92
- ## Examples by Use Case
93
-
94
- ### Dynamic Field Display
95
-
96
- ```javascript
97
- // Show additional input field when other is selected
98
- IF(HASOTHER($industry), "Specify industry: " + OTHER($industry), "")
99
- ```
100
-
101
- ### Validation Rules
102
-
103
- ```javascript
104
- // Require other field to be non-empty when selected
105
- AND(HASOTHER($reason), OTHER($reason).length > 3)
106
- ```
107
-
108
- ### Conditional Processing - SingleChoiceField
109
-
110
- ```javascript
111
- // Different processing based on other selection
112
- IF(HASOTHER($payment_method), "Custom payment: " + OTHER($payment_method), "Standard payment")
113
- ```
114
-
115
- ### Conditional Processing - MultiChoiceField
116
-
117
- ```javascript
118
- // Different processing based on other selection in multi-choice
119
- IF(HASOTHER($skills), "Custom skill: " + OTHER($skills), "Standard skills: " + CHOICELABELS($skills).join(", "))
120
- ```
121
-
122
- ### Form Completion
123
-
124
- ```javascript
125
- // Check if form is complete including other fields
126
- AND(CHOICEVALUE($category) !== null, IF(HASOTHER($category), OTHER($category).length > 0, true))
127
- ```
128
-
129
- ## Field Type Compatibility
130
-
131
- - **SingleChoiceField**: Single selection with optional other input
132
- - **MultiChoiceField**: Multiple selections with optional other input
133
- - **Note**: User can only add 1 other option regardless of field type