form0-core 0.3.0 → 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.
- package/README.md +63 -0
- package/package.json +5 -2
- package/src/builtins/builtin-definitions.js +320 -0
- package/src/builtins/choice/choicelabel.js +2 -17
- package/src/builtins/choice/choicelabels.js +2 -17
- package/src/builtins/choice/choicevalue.js +2 -20
- package/src/builtins/choice/choicevalues.js +2 -17
- package/src/builtins/choice/hasother.js +2 -20
- package/src/builtins/choice/other.js +2 -20
- package/src/builtins/control/eval.js +78 -31
- package/src/builtins/control/setresult.js +29 -17
- package/src/builtins/date/dateadd.js +24 -0
- package/src/builtins/date/days.js +22 -0
- package/src/builtins/event/control/off.js +3 -27
- package/src/builtins/event/control/on.js +3 -19
- package/src/builtins/event/event-operations-collector.js +33 -9
- package/src/builtins/event/field/setvalue.js +3 -32
- package/src/builtins/event/ui/alert.js +3 -11
- package/src/builtins/logical/and.js +2 -17
- package/src/builtins/logical/array.js +2 -35
- package/src/builtins/logical/count.js +2 -20
- package/src/builtins/logical/counta.js +2 -20
- package/src/builtins/logical/countblank.js +2 -20
- package/src/builtins/logical/if.js +2 -20
- package/src/builtins/logical/or.js +2 -17
- package/src/builtins/math/abs.js +2 -20
- package/src/builtins/math/ceiling.js +2 -20
- package/src/builtins/math/cos.js +2 -20
- package/src/builtins/math/round.js +2 -23
- package/src/builtins/math/sin.js +2 -20
- package/src/builtins/registry.js +23 -40
- package/src/builtins/schema/datanames.js +9 -20
- package/src/builtins/schema/form.js +2 -20
- package/src/builtins/string/upper.js +2 -20
- package/src/engine/calculation-diagnostics.js +107 -0
- package/src/engine/calculation.js +65 -32
- package/src/engine/conditions.js +69 -3
- package/src/engine/evaluator.js +56 -18
- package/src/engine/event-operation-scope.js +61 -0
- package/src/engine/event-source.js +164 -0
- package/src/engine/events.js +111 -23
- package/src/engine/form-engine.js +61 -16
- package/src/engine/warning-system.js +7 -5
- package/src/schema/field-specs.js +2 -2
- package/src/security/validation.js +10 -8
- package/src/utilities/calculation-editor.js +42 -6
- package/src/utilities/date-utils.js +72 -0
- package/src/builtins/docs/choice/choicelabel.mdx +0 -110
- package/src/builtins/docs/choice/choicelabels.mdx +0 -230
- package/src/builtins/docs/choice/choicevalue.mdx +0 -109
- package/src/builtins/docs/choice/choicevalues.mdx +0 -196
- package/src/builtins/docs/choice/hasother.mdx +0 -133
- package/src/builtins/docs/choice/other.mdx +0 -150
- package/src/builtins/docs/control/setresult.mdx +0 -203
- package/src/builtins/docs/event/field/setvalue.mdx +0 -239
- package/src/builtins/docs/index.mdx +0 -234
- package/src/builtins/docs/logical/and.mdx +0 -141
- package/src/builtins/docs/logical/if.mdx +0 -94
- package/src/builtins/docs/logical/or.mdx +0 -191
- package/src/builtins/docs/overview.mdx +0 -255
|
@@ -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
|
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "OTHER Builtin"
|
|
3
|
-
description: "Retrieve the other option value from choice field (SingleChoiceField or MultiChoiceField)"
|
|
4
|
-
category: "choice"
|
|
5
|
-
tags: ["choice", "other", "custom", "multichoice"]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# OTHER Function
|
|
9
|
-
|
|
10
|
-
The `OTHER` builtin retrieves the other label if the user entered an other option in a choice field, returning `null` if no other option is present. Works with both SingleChoiceField (single selection) and MultiChoiceField (multiple selections).
|
|
11
|
-
|
|
12
|
-
## Syntax
|
|
13
|
-
|
|
14
|
-
```javascript
|
|
15
|
-
OTHER(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 the other label as a string if user entered an other option, `null` otherwise.
|
|
27
|
-
|
|
28
|
-
## Examples
|
|
29
|
-
|
|
30
|
-
### Basic Usage - SingleChoiceField
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
// Get the other value from single choice field
|
|
34
|
-
OTHER($city)
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Basic Usage - MultiChoiceField
|
|
38
|
-
|
|
39
|
-
```javascript
|
|
40
|
-
// Get the other value from multi choice field
|
|
41
|
-
OTHER($colors)
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Conditional Logic
|
|
45
|
-
|
|
46
|
-
```javascript
|
|
47
|
-
// Use in conditional expressions for single choice
|
|
48
|
-
IF(HASOTHER($city), "Custom city: " + OTHER($city), "No custom city entered")
|
|
49
|
-
|
|
50
|
-
// Use in conditional expressions for multi choice
|
|
51
|
-
IF(HASOTHER($colors), "Custom color: " + OTHER($colors), "No custom color entered")
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### Display Logic
|
|
55
|
-
|
|
56
|
-
```javascript
|
|
57
|
-
// Show other value in display
|
|
58
|
-
"Additional info: " + OTHER($comments)
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Validation
|
|
62
|
-
|
|
63
|
-
```javascript
|
|
64
|
-
// Validate other input length
|
|
65
|
-
OTHER($reason).length > 10
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
## Common Use Cases
|
|
69
|
-
|
|
70
|
-
- **Custom input display**: Show user-entered custom values
|
|
71
|
-
- **Conditional logic**: Make decisions based on other option content
|
|
72
|
-
- **Validation**: Validate the content of other options
|
|
73
|
-
- **Data processing**: Extract custom values for further processing
|
|
74
|
-
- **Multi-choice support**: Works seamlessly with both single and multiple choice fields
|
|
75
|
-
|
|
76
|
-
## Best Practices
|
|
77
|
-
|
|
78
|
-
1. **Check with HASOTHER**: Always use `HASOTHER()` to check if other option exists before using `OTHER()`
|
|
79
|
-
2. **Handle null values**: Always handle the case where `OTHER()` returns null
|
|
80
|
-
3. **Validation**: Validate other inputs for length, format, etc.
|
|
81
|
-
4. **User feedback**: Provide clear feedback about other option values
|
|
82
|
-
5. **Multi-choice compatibility**: Works with both SingleChoiceField and MultiChoiceField
|
|
83
|
-
|
|
84
|
-
## Related Functions
|
|
85
|
-
|
|
86
|
-
- [`HASOTHER`](./hasother.mdx) - Check if other option is selected
|
|
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
|
-
### Custom Input Display - SingleChoiceField
|
|
95
|
-
|
|
96
|
-
```javascript
|
|
97
|
-
// Display custom input with fallback
|
|
98
|
-
IF(HASOTHER($industry), "Industry: " + OTHER($industry), "Industry: " + CHOICELABEL($industry))
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Custom Input Display - MultiChoiceField
|
|
102
|
-
|
|
103
|
-
```javascript
|
|
104
|
-
// Display custom input with fallback for multi-choice
|
|
105
|
-
IF(HASOTHER($skills), "Custom skill: " + OTHER($skills), "Skills: " + CHOICELABELS($skills).join(", "))
|
|
106
|
-
```
|
|
107
|
-
|
|
108
|
-
### Validation Rules
|
|
109
|
-
|
|
110
|
-
```javascript
|
|
111
|
-
// Ensure other input meets requirements
|
|
112
|
-
IF(HASOTHER($reason), OTHER($reason).length >= 5, true)
|
|
113
|
-
```
|
|
114
|
-
|
|
115
|
-
### Data Processing - SingleChoiceField
|
|
116
|
-
|
|
117
|
-
```javascript
|
|
118
|
-
// Process other values differently
|
|
119
|
-
IF(HASOTHER($category), "CUSTOM: " + OTHER($category), "STANDARD: " + CHOICEVALUE($category))
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
### Data Processing - MultiChoiceField
|
|
123
|
-
|
|
124
|
-
```javascript
|
|
125
|
-
// Process other values differently for multi-choice
|
|
126
|
-
IF(HASOTHER($categories), "CUSTOM: " + OTHER($categories), "STANDARD: " + CHOICEVALUES($categories).join(", "))
|
|
127
|
-
```
|
|
128
|
-
|
|
129
|
-
### Form Summary
|
|
130
|
-
|
|
131
|
-
```javascript
|
|
132
|
-
// Include other values in form summary
|
|
133
|
-
"Additional comments: " + (HASOTHER($comments) ? OTHER($comments) : "None")
|
|
134
|
-
```
|
|
135
|
-
|
|
136
|
-
## Null Handling
|
|
137
|
-
|
|
138
|
-
Always handle the null case when using `OTHER()`:
|
|
139
|
-
|
|
140
|
-
```javascript
|
|
141
|
-
// Safe usage with null check
|
|
142
|
-
IF(HASOTHER($field), OTHER($field) || "No value", "Standard selection")
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
## Field Type Compatibility
|
|
146
|
-
|
|
147
|
-
- **SingleChoiceField**: Single selection with optional other input
|
|
148
|
-
- **MultiChoiceField**: Multiple selections with optional other input
|
|
149
|
-
- **Note**: User can only add 1 other option regardless of field type
|
|
150
|
-
- **Return value**: Always returns a single string (the other label) or null
|
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: "SETRESULT Builtin"
|
|
3
|
-
description: "Set calculation results in form0 expressions"
|
|
4
|
-
category: "control"
|
|
5
|
-
tags: ["calculation", "result", "output"]
|
|
6
|
-
---
|
|
7
|
-
|
|
8
|
-
# SETRESULT Function
|
|
9
|
-
|
|
10
|
-
The `SETRESULT` builtin sets a result value that can be consumed by the form0 engine, typically used in calculations to define the final output value.
|
|
11
|
-
|
|
12
|
-
## Syntax
|
|
13
|
-
|
|
14
|
-
```javascript
|
|
15
|
-
SETRESULT(value)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Parameters
|
|
19
|
-
|
|
20
|
-
| Parameter | Type | Description |
|
|
21
|
-
|-----------|------|-------------|
|
|
22
|
-
| `value` | `any` | The value to set as the result |
|
|
23
|
-
|
|
24
|
-
## Return Value
|
|
25
|
-
|
|
26
|
-
Returns the same value that was passed in, while internally storing it as the calculation result.
|
|
27
|
-
|
|
28
|
-
## Examples
|
|
29
|
-
|
|
30
|
-
### Basic Calculation
|
|
31
|
-
|
|
32
|
-
```javascript
|
|
33
|
-
// Calculate total price with tax
|
|
34
|
-
SETRESULT(price * quantity * (1 + taxRate))
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Conditional Results
|
|
38
|
-
|
|
39
|
-
```javascript
|
|
40
|
-
// Set discount amount based on user type
|
|
41
|
-
SETRESULT(IF(user.isPremium, price * 0.2, price * 0.05))
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
### Complex Business Logic
|
|
45
|
-
|
|
46
|
-
```javascript
|
|
47
|
-
// Calculate shipping cost with multiple factors
|
|
48
|
-
SETRESULT(
|
|
49
|
-
IF(country === "US",
|
|
50
|
-
IF(orderValue > 50, 0, 5.99),
|
|
51
|
-
IF(orderValue > 100, 10, 15.99)
|
|
52
|
-
)
|
|
53
|
-
)
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
### Score Calculations
|
|
57
|
-
|
|
58
|
-
```javascript
|
|
59
|
-
// Calculate user credit score
|
|
60
|
-
SETRESULT(
|
|
61
|
-
(creditHistory * 0.35) +
|
|
62
|
-
(paymentHistory * 0.35) +
|
|
63
|
-
(creditUtilization * 0.30)
|
|
64
|
-
)
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
### Dynamic Field Values
|
|
68
|
-
|
|
69
|
-
```javascript
|
|
70
|
-
// Set field value based on other fields
|
|
71
|
-
SETRESULT(
|
|
72
|
-
IF(AND(firstName.length > 0, lastName.length > 0),
|
|
73
|
-
firstName + " " + lastName,
|
|
74
|
-
"Anonymous User"
|
|
75
|
-
)
|
|
76
|
-
)
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
## How It Works
|
|
80
|
-
|
|
81
|
-
1. **Calculation Execution**: The form0 engine executes your calculation expression
|
|
82
|
-
2. **Result Storage**: `SETRESULT` stores the value internally
|
|
83
|
-
3. **Result Consumption**: The engine retrieves the stored result
|
|
84
|
-
4. **Value Return**: The function also returns the value for use in expressions
|
|
85
|
-
|
|
86
|
-
## Common Use Cases
|
|
87
|
-
|
|
88
|
-
- **Price calculations**: Total cost, discounts, taxes
|
|
89
|
-
- **Score computations**: Credit scores, ratings, assessments
|
|
90
|
-
- **Field aggregations**: Combining multiple fields into one result
|
|
91
|
-
- **Conditional outputs**: Different results based on conditions
|
|
92
|
-
- **Business rule results**: Complex logic outcomes
|
|
93
|
-
|
|
94
|
-
## Best Practices
|
|
95
|
-
|
|
96
|
-
1. **Single result per calculation**: Use only one `SETRESULT` per expression
|
|
97
|
-
2. **Clear value types**: Ensure the result type matches expectations
|
|
98
|
-
3. **Handle edge cases**: Consider null/undefined values
|
|
99
|
-
4. **Document complex logic**: Add comments for complex calculations
|
|
100
|
-
|
|
101
|
-
## Important Notes
|
|
102
|
-
|
|
103
|
-
- **Single use**: Only one `SETRESULT` should be called per calculation
|
|
104
|
-
- **Last wins**: If called multiple times, the last value is used
|
|
105
|
-
- **Pass-through**: The function returns the value, so it can be used in expressions
|
|
106
|
-
- **Type preservation**: The result maintains its original type
|
|
107
|
-
|
|
108
|
-
## Related Functions
|
|
109
|
-
|
|
110
|
-
- [`IF`](../logical/if.mdx) - Conditional logic for result selection
|
|
111
|
-
- [`AND`](../logical/and.mdx) - Multiple condition checks
|
|
112
|
-
- [`OR`](../logical/or.mdx) - Alternative condition checks
|
|
113
|
-
|
|
114
|
-
## Examples by Use Case
|
|
115
|
-
|
|
116
|
-
### E-commerce Pricing
|
|
117
|
-
|
|
118
|
-
```javascript
|
|
119
|
-
// Calculate final price with all factors
|
|
120
|
-
SETRESULT(
|
|
121
|
-
(basePrice * quantity) +
|
|
122
|
-
shippingCost +
|
|
123
|
-
(taxableAmount * taxRate) -
|
|
124
|
-
discountAmount
|
|
125
|
-
)
|
|
126
|
-
```
|
|
127
|
-
|
|
128
|
-
### User Scoring
|
|
129
|
-
|
|
130
|
-
```javascript
|
|
131
|
-
// Calculate engagement score
|
|
132
|
-
SETRESULT(
|
|
133
|
-
(loginFrequency * 0.3) +
|
|
134
|
-
(activityLevel * 0.4) +
|
|
135
|
-
(socialSharing * 0.3)
|
|
136
|
-
)
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
### Form Validation Results
|
|
140
|
-
|
|
141
|
-
```javascript
|
|
142
|
-
// Set validation status
|
|
143
|
-
SETRESULT(
|
|
144
|
-
IF(AND(email.isValid, phone.isValid, name.length > 0),
|
|
145
|
-
"valid",
|
|
146
|
-
"invalid"
|
|
147
|
-
)
|
|
148
|
-
)
|
|
149
|
-
```
|
|
150
|
-
|
|
151
|
-
### Financial Calculations
|
|
152
|
-
|
|
153
|
-
```javascript
|
|
154
|
-
// Calculate loan eligibility
|
|
155
|
-
SETRESULT(
|
|
156
|
-
IF(AND(creditScore > 650, income > 50000, debtRatio < 0.4),
|
|
157
|
-
"approved",
|
|
158
|
-
"denied"
|
|
159
|
-
)
|
|
160
|
-
)
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
### Progress Tracking
|
|
164
|
-
|
|
165
|
-
```javascript
|
|
166
|
-
// Calculate completion percentage
|
|
167
|
-
SETRESULT(
|
|
168
|
-
Math.round(
|
|
169
|
-
(completedSteps / totalSteps) * 100
|
|
170
|
-
)
|
|
171
|
-
)
|
|
172
|
-
```
|
|
173
|
-
|
|
174
|
-
## Advanced Examples
|
|
175
|
-
|
|
176
|
-
### Multi-step Calculation
|
|
177
|
-
|
|
178
|
-
```javascript
|
|
179
|
-
// Calculate insurance premium
|
|
180
|
-
SETRESULT(
|
|
181
|
-
IF(age < 25,
|
|
182
|
-
basePremium * 1.5,
|
|
183
|
-
IF(age > 65,
|
|
184
|
-
basePremium * 1.2,
|
|
185
|
-
basePremium
|
|
186
|
-
)
|
|
187
|
-
) *
|
|
188
|
-
IF(hasAccidents, 1.3, 1.0) *
|
|
189
|
-
IF(location === "urban", 1.1, 0.9)
|
|
190
|
-
)
|
|
191
|
-
```
|
|
192
|
-
|
|
193
|
-
### Data Aggregation
|
|
194
|
-
|
|
195
|
-
```javascript
|
|
196
|
-
// Calculate average rating
|
|
197
|
-
SETRESULT(
|
|
198
|
-
IF(reviewCount > 0,
|
|
199
|
-
(rating1 + rating2 + rating3 + rating4 + rating5) / reviewCount,
|
|
200
|
-
0
|
|
201
|
-
)
|
|
202
|
-
)
|
|
203
|
-
```
|