Can a form field be validated asynchronously and display the error message?
1

Can a form field be validated asynchronously and display the error message? If yes, where can I see an example of the response that the endpoint should return?

Erne
Asked about 6 months ago
Selected Answer
1

Yes, it's possible to do this leveraging the error-messages object within a Form object (read more here).

For example, your Flow JSON definition could look like this:

{
  "version": "3.1",
  "screens": [
    {
      "id": "DEMO_SCREEN",
      "title": "Demo Screen",
      "terminal": true,
      "success": true,
      "data": {
        "name_error": {
          "type": "string",
          "__example__": "Name is invalid"
        }
      },
      "layout": {
        "type": "SingleColumnLayout",
        "children": [
          {
            "type": "Form",
            "name": "user_data",
            "init-values": {
              "first_name": "Jon"
            },
            "error-messages": {
              "first_name": "${data.name_error}"
            },
            "children": [
              {
                "type": "TextInput",
                "required": true,
                "label": "First name",
                "name": "first_name"
              },
              {
                "type": "Footer",
                "label": "Submit data",
                "on-click-action": {
                  "name": "complete",
                  "payload": {
                    "name": "${form.first_name}"
                  }
                }
              }
            ]
          }
        ]
      }
    }
  ]
}

For this example Flow JSON, your data_exchange response can control the error message via the name_error property in the data payload.

June 17 at 3:28 AM
Bar