自适应卡在提交时清除输入 [英] Adaptive Card clears input on submit

查看:69
本文介绍了自适应卡在提交时清除输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从Microsoft Teams机器人中,我发送一个带有输入字段和Submit操作的Adaptive Card.当用户单击Submit时,我收到了输入的数据,但表单字段已清除.

From a Microsoft Teams bot I send an Adaptive Card with input fields and a Submit action. When the user clicks Submit I receive the data entered but the form fields are cleared.

这是为什么?我究竟做错了什么?这种行为非常令人讨厌,因为我无法验证输入并要求用户进行更正.

Why is this? What am I doing wrong? This behavior is extremely annoying as I can't verify the input and ask the user to correct it.

这发生在桌面上的Teams应用程序,浏览器中的Teams,网页中的Teams网络聊天以及Bot仿真器中.在仿真器中,该字段足以释放焦点.

This happens in the desktop Teams app, Teams in a browser, Teams webchat in a web page and the Bot Emulator. In the Emulator it suffices for the field to loose focus.

万一重要,我可以使用nodejs.

In case it matters I use nodejs.

推荐答案

您没有做错任何事情.这就是自适应卡在团队中的工作方式,也许是表示数据已成功发送到机器人的一种方式.不过,您可能可以采取一些措施来解决问题.

You're not doing anything wrong. That's just how Adaptive Cards work in Teams, perhaps as a way to signify that the data has been sent to the bot successfully. There may be something you can do to fix your problem though.

自适应卡输入字段具有value属性,该属性允许您指定字段的初始值.如果将卡片发送给用户,并且输入字段的value属性已填充,则这些字段不会为空.这意味着您可以发送此类卡片作为更新而不是新活动,并且看起来该卡片已被修改,因为Teams支持更新活动.如果更新使用的是同一张卡,但用户输入的值相同,则该卡看起来将保持不变,这将解决您的值消失的问题.

Adaptive Card input fields have a value property that allows you to specify the field's initial value. If you send a card to the user and the input fields' value properties are populated, the fields won't be empty. This means you can send such a card as an update instead of a new activity and it will look like the card has been modified in place, since Teams supports updating activities. If the update uses the same card but with the values the user entered then it will look like the card remains unchanged, which would fix your problem of the values disappearing.

有一个关于将输入字段动态添加到自适应卡的问题,并且 answer 包含保留输入字段的示例代码值:

There was a question about dynamically adding input fields to Adaptive Cards, and the answer contains sample code that preserves input field values:

var inputId = `text${i}`;
body.push({
    type: "Input.Text",
    id: inputId,
    value: cardData[inputId] // This is where the value is preserved
});

如果您希望通过可安装在NuGet软件包中的预构建代码使整个过程变得更容易,请随时在GitHub上表达对这些想法的支持:
Bot.Builder.Community.AdaptiveCards
AdaptiveCard提示

If you want this whole process to be made easier with prebuilt code that you can install in NuGet packages, feel free to voice your support for these ideas on GitHub:
Bot.Builder.Community.AdaptiveCards
AdaptiveCard Prompt

这篇关于自适应卡在提交时清除输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆