Platform
Author or host
Host Rendering Cards
Version of SDK
npm Adaptive Cards v1.2.0
Issue
Per issue microsoft/BotFramework-WebChat#2192
Adaptive inputs of type Input.Number don't display the value 0.

To Reproduce
Steps to reproduce:
- Go to Adaptive Cards Designer
- Select
Bot Framework WebChat as the host app
- Paste the following json in the
Card Payload Editor:
{
"type": "AdaptiveCard",
"actions": [
{
"title": "Submit",
"type": "Action.Submit"
}
],
"body": [
{
"text": "Input 1",
"type": "TextBlock"
},
{
"id": "InputOne",
"placeholder": "Input 1 Placeholder",
"type": "Input.Number",
"value": 10
},
{
"text": "Input 2",
"type": "TextBlock"
},
{
"id": "InputTwo",
"placeholder": "Input 2 Placeholder",
"type": "Input.Number",
"value": -10
},
{
"text": "Input 3",
"type": "TextBlock"
},
{
"id": "InputThree",
"placeholder": "Input 3 Placeholder",
"type": "Input.Number",
"value": 0
}
],
"$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"version": "1.0"
}
- See that the third input is not displaying the expected value
Likely cause
It looks like Adaptive Card's Input class's parse method uses the getStringValue utility to set the input's default value. The function uses a ternary to either return the value set in the Adaptive Card JSON as a string or the default value which would be undefined. In the case of the value being 0, the getStringValue function would return undefined.
Input Parse Method
parse(json: any, errors?: Array<HostConfig.IValidationError>) {
super.parse(json, errors);
this.id = Utils.getStringValue(json["id"]);
this.defaultValue = Utils.getStringValue(json["value"]);
if (AdaptiveCard.useBuiltInInputValidation) {
let jsonValidation = json["validation"];
if (jsonValidation) {
this.validation.parse(jsonValidation);
}
}
}
Get String Value Method
export function getStringValue(obj: any, defaultValue: string = undefined): string {
return obj ? obj.toString() : defaultValue;
}
Possible Fix
The getStringValue method would likely have to be changed to check if the value is not undefined or equal to zero.
export function getStringValue(obj: any, defaultValue: string = undefined): string {
return (typeof obj !== 'undefined') ? obj.toString() : defaultValue;
}
Platform
Author or host
Host Rendering Cards
Version of SDK
npm Adaptive Cards v1.2.0
Issue
Per issue microsoft/BotFramework-WebChat#2192
Adaptive inputs of type
Input.Numberdon't display the value0.To Reproduce
Steps to reproduce:
Bot Framework WebChatas the host appCard Payload Editor:Likely cause
It looks like Adaptive Card's
Inputclass'sparsemethod uses thegetStringValueutility to set the input's default value. The function uses a ternary to either return the value set in the Adaptive Card JSON as a string or the default value which would beundefined. In the case of the value being0, thegetStringValuefunction would returnundefined.Input Parse Method
Get String Value Method
Possible Fix
The
getStringValuemethod would likely have to be changed to check if the value is not undefined or equal to zero.