Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 94c660f

Browse files
authored
add number validation (#520)
* add number validation * removed unnecessary codes
1 parent 8119b35 commit 94c660f

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

packages/dialog/templates/en-us/common.lg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,19 @@ Which value do you want for @{name(property)}?
2424
# askNumber(property)
2525
- IF: @{dialogClass.schema.properties[property].minimum && dialogClass.schema.properties[property].maximum}
2626
- Enter a number for @{name(property)} between @{dialogClass.schema.properties[property].minimum} and @{dialogClass.schema.properties[property].maximum}
27+
- ELSEIF: @{dialogClass.schema.properties[property].minimum}
28+
- Enter a number for @{name(property)} that is greater than @{dialogClass.schema.properties[property].minimum}
29+
- ELSEIF: @{dialogClass.schema.properties[property].maximum}
30+
- Enter a number for @{name(property)} that is less than @{dialogClass.schema.properties[property].maximum}
2731
- ELSE:
2832
- Enter a number for @{name(property)}
2933

34+
# numberValidation(property, number)
35+
- IF: @{less(number, dialogClass.schema.properties[property].minimum)}
36+
- @{number} is less than the minimum value @{dialogClass.schema.properties[property].minimum}.
37+
- ELSEIF: @{greater(number, dialogClass.schema.properties[property].maximum)}
38+
- @{number} is greater than the maximum value @{dialogClass.schema.properties[property].maximum}.
39+
3040
# askString(property)
3141
- ```
3242
@{askHelp()}

packages/dialog/templates/numberSetnumber.dialog.lg

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,33 @@
1111
"entity": "number",
1212
"actions": [
1313
{
14-
"$kind": "Microsoft.SendActivity",
15-
"activity": "@{callSetMessage()}"
16-
},
17-
{
18-
"$kind": "Microsoft.SetProperty",
19-
"property": "$@{property}",
20-
"value": "=@number"
14+
"$kind": "Microsoft.IfCondition",
15+
"condition":"or(less(@number, dialogClass.schema.properties['@{property}'].minimum), greater(@number, dialogClass.schema.properties['@{property}'].maximum))",
16+
"actions":[
17+
{
18+
"$kind": "Microsoft.SendActivity",
19+
"activity": "@{callNumberAlert()}"
20+
}
21+
],
22+
"elseActions":[
23+
{
24+
"$kind": "Microsoft.SendActivity",
25+
"activity": "@{callSetMessage()}"
26+
},
27+
{
28+
"$kind": "Microsoft.SetProperty",
29+
"property": "$@{property}",
30+
"value": "=@number"
31+
}
32+
]
2133
}
34+
2235
]
2336
}
2437
```
2538

39+
# callNumberAlert
40+
- @\{numberValidation('@{property}', @number)}
41+
2642
# callSetMessage
2743
- @\{setPropertyMessage('@{property}', @number)}

0 commit comments

Comments
 (0)