Botframework-webchat: AdaptiveCards: Number inputs don't display the value 0

Created on 16 Jul 2019  路  5Comments  路  Source: microsoft/BotFramework-WebChat

Version

Latest version from CDN

Description

Adaptive inputs of type Input.Number don't display the value 0.

image

To Reproduce

Steps to reproduce:

  1. Go to Adaptive Cards Designer
  2. Select Bot Framework WebChat as the host app
  3. 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"
    }
    ~
  4. See that the third input is not displaying the expected value

Additional Info

This card was created using the C# AdaptiveCards package 1.2.0
This card will render correctly in the Emulator

[Bug]

Bot Services Bug Adaptive Cards customer-replied-to customer-reported front-burner

Most helpful comment

I was able to reproduce this by sending the same json to Mock Bot for rendering

copy-pasting the json to the Adaptive Cards schema reproduces this issue, but manually assigning the value 0 in the schema editor shows the value 0 as expected.

All 5 comments

I was able to reproduce this by sending the same json to Mock Bot for rendering

copy-pasting the json to the Adaptive Cards schema reproduces this issue, but manually assigning the value 0 in the schema editor shows the value 0 as expected.

Was able to replicate.
Wrapping the 0 with quotation marks seems to work.
Other values work with and without the quotation marks.

This issue is possibly related to a verification if the input has a value or not.
Using the browser console you can assert the following:

true && 10 => true
true && "10" => true
true && "0" => true
true && 0 => false

This card was created using the C# Adaptive Cards package
Will update the issue with this info

@jodufra

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;
}

The getStringValue method would likely have to be changed to check if the value is not undefined or equals zero.

export function getStringValue(obj: any, defaultValue: string = undefined): string {
    return (obj || obj === 0) ? obj.toString() : defaultValue;
}

@jodufra

I opened an issue in the Adaptive Cards Repo. You can track it here https://github.com/microsoft/AdaptiveCards/issues/3237. Thank you for pointing out this issue.

Adaptive Cards just merged a fix for this issue. Should be resolved in Web Chat when we bump to the next version.

Was this page helpful?
0 / 5 - 0 ratings