question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add IsRequired to Inputs for basic validation

See original GitHub issue

Implementation status

  • .NET
  • Android
  • iOS
  • JavaScript
  • UWP
  • Documentation

Problem

Right now, users can submit a response with text boxes and other inputs that are completely empty. It’d be helpful if we at least added a property that makes an input required.

This probably should be linked to the action somehow, since there might be some actions on the card that require no inputs, while another action on the same card requires all inputs.

Asks

  • Author - pritambaldota
  • Author - thirteenflt

Research

  • Telerik - Doing Form Validation Right In Mobile Applications
    • Ideally only validate one field at a time with an error at the top to not overwhelm users
    • If can’t do that, use contextual validation errors
    • Do NOT disable the button till required inputs are entered
  • Form validation best practices
    • Display contextually
      • On wide screens, to the right of the input is ideal
      • On narrow screens, below the input is ideal (no space to the right)
    • Display at the right time
      • Right after the user submits the information
      • Ideally instant validation (after they move to the next text field) is best
      • Instant validation that always has a green checkmark can be counter-intuitive for things like entering your name: “What is this green tick telling me, I know my own name?!”
    • Use the right color (red for problems, green for success)
    • Use clear language (have a conversation with the user)
  • UX form validation

Solution

Add a requiredInputs property on Action elements.

Schema

New property on Action

Property Type Required Description
requiredInputs string[] false Specifies which inputs are required. If values are missing from those inputs when clicking this action, validation errors will be displayed and the action won’t be performed.

OPEN QUESTION: Should we also allow authors to provide custom text for the validation error? Maybe that’s a vNext feature? Or maybe we do it now? It probably shouldn’t be required for authors to provide that text though, there’s something nice about not needing to provide that text.

Example

{
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "text": "Please confirm your username"
    },
    {
      "type": "Input.Text",
      "id": "username",
      "placeholder": "Username"
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Confirm",
      "data": "action=confirm",
      "requiredInputs": [
        "username"
      ]
    },
    {
      "type": "Action.Submit",
      "title": "Cancel",
      "data": "action=cancel"
    }
  ]
}

Initial state image

User clicks Confirm, we show validation errors (and trigger event to host telling host where it needs to scroll to, in case some of the invalid fields were off-screen) image

User changes the input value, we remove the validation error. We’ll re-validate upon button press again. So even if they type “a” and then delete it, the validation error should remain removed.

image

Note that we do NOT place the validation above the input, since it breaks the flow of the header text related to the input. And we can’t place the validation above the header text, since inputs don’t have a header property.

image

Other inputs

image image

Host Config

New validation object that allows hosts to specify what required text they want. This is so that hosts can localize to the language they’re running in. Plus, their app might have a different wording for validation errors, like “Value required”.

{
  "fontFamily": "Segoe UI",
  "validation": {
    "requiredText": "Required"
  }
}

Down-level impact

Medium. Authors need to expect that users running down-level can still submit the card with empty inputs (most concerning for new authors who might assume that required property works, existing authors should already have that logic).

Renderer Requirements

  1. A renderer must respect the requiredInputs property and not allow action execution until the required inputs are fulfilled.
  2. A renderer should display the validation errors as described in this spec.
  3. If displaying validation errors, a renderer must use the text provided in the host config. If none is specified, use "Required"

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:7
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Kartik1607commented, Mar 7, 2018

In .Net, there is a field called IsRequired. Apparently it was removed for god knows why. Here is the link

0reactions
andrewleadercommented, Feb 20, 2019

Closing as dupe of #1978

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validating a form when either a "select" OR "input" is required
Here's a function that do exactly what you want and can handle any form you want, as long as they have the same...
Read more >
How to perform form validation for a required field in HTML
1. Required attribute: If you want to make an input mandatory to be entered by the user, you can use the required attribute....
Read more >
Validating Input | Web Accessibility Initiative (WAI)
Validating required input ​​ Forms frequently include required input that needs to be clearly identified using labels. Also, the required attribute can be...
Read more >
Client-side form validation - Learn web development | MDN
The simplest HTML validation feature is the required attribute. To make an input mandatory, add this attribute to the element.
Read more >
Styling Form Inputs in CSS With :required, :optional, :valid ...
Adding the :focus pseudo-class​​ There are two key changes in the above CSS: input:required:valid applies a success state only to required inputs ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found