M365 Development · SharePoint · Viva Connections

How to use text input in Adaptive Card Extensions’ card views

To use an input field on an Adaptive Card Extension (ACE), you could only do it on a quick view of the card. Since SPFx v1.18, it is possible to use a text input component directly on an Adaptive Card Extension’s card views.

For instance, if your adaptive card main purpose is to get a simple input from users, you could really benefit from this new feature.

This blog post demonstrates how to implement this feature.

Content

  1. Requirements
    1. New adaptive card
    2. Existing adaptive card
  2. Use the new default class for card views
  3. From the card footer
  4. From the card body
  5. References

Requirements

New adaptive card

If you want to implement the feature on a new adaptive card extension, perform the following steps:

  1. Make sur you have the latest version of the SharePoint Framework installed : npm install @microsoft/generator-sharepoint@latest --global
  2. Run yo @microsoft/sharepoint
  3. Select Generic Card Template in the generator

Existing adaptive card

You can also implement this feature on an already existing ACE created with an on older SPFx version. To do so, you need to migrate your Adaptive Card Extension to SharePoint Framework v1.18.

Since SPFx v1.18 new classes and other architectural changes, migration to this version requires additional steps. You can find more details here: Migrate Adaptive Card Extensions to SharePoint Framework v1.18

Use the new default class for card views

SPFx v1.18 introduce BaseComponentsCardView as the new default class for Adaptive Card Extensions card views. You can use this new class to specify components that you want to display in a card view:

The first option that you have, is to use a text input component in the footer of your card view.

In the BaseComponentsCardView class, define the BasicCardView as follows:

As you can see, the componentName property of the footer is defined as textInput. You also have the following properties:

PropertyDescription
idId of the component
placeholderPlaceholder of the text input component
button/iconDefine the icon of the button
button/actionAction to perform when the button is clicked

From the card body

The second option is to use an text input component in the body of your card view.

In the BaseComponentsCardView class, define the TextInputCardView as follows:

Here the textInput component is defined in the body. You can set the following properties:

PropertyDescription
idId of the component
placeholderPlaceholder of the text input component
iconBeforeDefine the icon on the left-hand side of the input component.

Note that in this case the button is still defined on the footer part of the Adaptive Card Extension.

References

Leave a Reply