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
Đã hỏi khoảng 4 tháng trước
Câu trả lời được chọn
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.

17 tháng 6 lúc 03:28
Bar