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.

Validator: Forms custom validation reporting

See original GitHub issue

We need to update validator for form to allow the following:

  • [custom-validation-reporting=show-first-on-submit|show-all-on-submit|as-you-go] can optionally appear on <form> elements
  • [visible-when-invalid=badInput|customError|patternMismatch|rangeOverflow|rangeUnderflow|stepMismatch|tooLong|typeMismatch|valueMissing] and [validation-for=id-regex] can optionally appear on any element in the document but must appear together on the element.

Here’s an example.

<form method="post"
      action-xhr="/form/echo-json/post"
      target="_blank"
      custom-validation-reporting="show-first-on-submit">
    <fieldset>
        <label>
            <span>Your name</span>
            <input type="text" name="name" id="name4" required pattern="\w+\s\w+">
            <span visible-when-invalid="valueMissing" validation-for="name4"></span>
            <span visible-when-invalid="patternMismatch" validation-for="name4">
                Please enter your first and last name separated by a space (e.g. Jane Miller)
            </span>
        </label>
        <label>
            <span>Your email</span>
            <input type="email" name="email" id="email4" required>
            <span visible-when-invalid="valueMissing" validation-for="email4"></span>
            <span visible-when-invalid="typeMismatch" validation-for="email4"></span>
        </label>
        <input type="submit" value="Subscribe">
    </fieldset>
</form>

ITI: #3343

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:8 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
Mars0817commented, Jul 16, 2018

amp-form visible-when-invalid has parameter tooLong,Why are there no parameters tooShort?

1reaction
mkhatibcommented, Sep 28, 2016

One more thing, we also need to whitelist submit-success and submit-error attributes on dependents of form.

This allows users to instruct form to render submit success/error messages.

<form...>
    <div submit-success>
        <template type="amp-mustache">
            Success! Thanks {{name}} for subscribing! Please make sure to check your email {{email}}
            to confirm!
        </template>
    </div>
    <div submit-error>
        <template type="amp-mustache">
            Oops! {{name}}, We apologies something went wrong. Please try again later.
        </template>
    </div>
</form>

If possible, also enforce that they need to have a single template element inside them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use Custom Form Validation in Angular - DigitalOcean
Learn how to create a custom validator in Angular for both template-driven and reactive forms.
Read more >
Client-side form validation - Learn web development | MDN
This validation is completely customizable, but you need to create it all (or use a library). Using built-in form validation. One of the...
Read more >
Validating form input - Angular
In reactive forms, add a custom validator by passing the function directly to the FormControl . reactive/hero-form-reactive.component.ts (validator functions)
Read more >
AMP Form custom-validation-reporting interact-and-submit
The attribute 'custom-validation-reporting' in tag 'FORM [method=POST]' is set to ... It said "The validator changes are now in production.
Read more >
Creating a custom validator based on the existing regular ...
To create a validation item: In the Content Editor, go to /sitecore/System/Settings/Forms/Validations . Right-click ...
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