Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add number validation #520

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/dialog/templates/en-us/common.lg
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,19 @@ Which value do you want for @{name(property)}?
# askNumber(property)
- IF: @{dialogClass.schema.properties[property].minimum && dialogClass.schema.properties[property].maximum}
- Enter a number for @{name(property)} between @{dialogClass.schema.properties[property].minimum} and @{dialogClass.schema.properties[property].maximum}
- ELSEIF: @{dialogClass.schema.properties[property].minimum}
- Enter a number for @{name(property)} that is greater than @{dialogClass.schema.properties[property].minimum}
- ELSEIF: @{dialogClass.schema.properties[property].maximum}
- Enter a number for @{name(property)} that is less than @{dialogClass.schema.properties[property].maximum}
- ELSE:
- Enter a number for @{name(property)}

# numberValidation(property, number)
- IF: @{dialogClass.schema.properties[property].minimum && less(number, dialogClass.schema.properties[property].minimum)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dialogClass.schema.properties[property].minimum [](start = 8, length = 48)

Do you need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, and removed.

- @{number} is less than the minimum value @{dialogClass.schema.properties[property].minimum}.
- ELSEIF: @{dialogClass.schema.properties[property].maximum && greater(number, dialogClass.schema.properties[property].maximum)}
- @{number} is greater than the maximum value @{dialogClass.schema.properties[property].maximum}.

# askString(property)
- ```
@{askHelp()}
Expand Down
30 changes: 23 additions & 7 deletions packages/dialog/templates/numberSetnumber.dialog.lg
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,33 @@
"entity": "number",
"actions": [
{
"$kind": "Microsoft.SendActivity",
"activity": "@{callSetMessage()}"
},
{
"$kind": "Microsoft.SetProperty",
"property": "$@{property}",
"value": "=@number"
"$kind": "Microsoft.IfCondition",
"condition":"or(and(dialogClass.schema.properties['@{property}'].minimum, less(@number, dialogClass.schema.properties['@{property}'].minimum)), and(dialogClass.schema.properties['@{property}'].maximum, greater(@number, dialogClass.schema.properties['@{property}'].maximum)))",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dialogClass.schema.properties['@{property}'].minimum [](start = 32, length = 52)

I don't think you need this. Less with null should be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

"actions":[
{
"$kind": "Microsoft.SendActivity",
"activity": "@{callNumberAlert()}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

callNumberAlert [](start = 35, length = 15)

Hmmm. Seems like we might be missing something here--a way to say do the same prompt again. In what we have generated so far, prompts tend to be predicatable, i.e. we keep doing the same one until fulfilled. If though someone used a Random secondary selector the prompt would be different. We don't need to fix this here, but it is something to think about.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. After check/alert/validation/help, we should have a way to let the users retry.

}
],
"elseActions":[
{
"$kind": "Microsoft.SendActivity",
"activity": "@{callSetMessage()}"
},
{
"$kind": "Microsoft.SetProperty",
"property": "$@{property}",
"value": "=@number"
}
]
}

]
}
```

# callNumberAlert
- @\{numberValidation('@{property}', @number)}

# callSetMessage
- @\{setPropertyMessage('@{property}', @number)}