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.

How add custom errors messages ?

See original GitHub issue

Hi,

How handle custom errors message ?

Let’s say we have a unsername filed : <AvGroup> <Label for="username">UserName</Label> <AvInput name="username" id="username" required minLength="6" maxLength="16" validate={{pattern: {value: '^[A-Za-z0-9]+$'}}} /> <AvFeedback>UserName is not valid</AvFeedback> </AvGroup>

I want to have errors like

  • “Your username must be between 6 and 16 characters”
  • “Your username must be composed only with letter and numbers”

How I easly do this with this lib ?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

11reactions
TheSharpieOnecommented, Jun 5, 2018

See this demo: https://stackblitz.com/edit/availity-reactstrap-validation-72-uu2ayn?file=Example.js preview: validation-errormessage

Here is the code:

import React from 'react';
import { Container } from 'reactstrap';
import { AvForm, AvField } from 'availity-reactstrap-validation';

class AvailityReactstrapValidationExample extends React.Component {
  render() {
    return (
      <Container className="py-4">
        <AvForm>
          <AvField name="username" label="Username" validate={{
              required: {value: true, errorMessage: "Please enter a username"},
              pattern: {value: '^[A-Za-z0-9]+$', errorMessage: 'Your username must be composed only with letter and numbers'},
              minLength: {value: 6, errorMessage: 'Your username must be between 6 and 16 characters'},
              maxLength: {value: 16, errorMessage: 'Your username must be between 6 and 16 characters'}
          }} />
          
          <AvField name="password" label="Password" type="password" required
            errorMessage="This error message is generic and gets overriden by the ones provided in the validate prop as those are more specific to a particular validation"
            validate={{
              pattern: {value: '^[A-Za-z0-9]+$', errorMessage: 'Your username must be composed only with letter and numbers'},
              minLength: {value: 6, errorMessage: 'Your username must be between 6 and 16 characters'},
              maxLength: {value: 16, errorMessage: 'Your username must be between 6 and 16 characters'}
          }} />
        </AvForm>
      </Container>
    );
  }
}
export default AvailityReactstrapValidationExample
1reaction
AbhaysinghBhosalecommented, Jun 29, 2020

i think reported issue is for AvInput instead of using AVField because in my case i want to attach copy icon with field but with av field that is not possible

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Make a Fake Error Message in Windows - wikiHow
Open the Notepad app. ... Copy and paste the following code into Notepad: ... Customize the button(s) of your error message. Replace Button...
Read more >
Custom errors, extending Error - The Modern JavaScript Tutorial
Create a class FormatError that inherits from the built-in SyntaxError class. It should support message , name and stack properties. Usage ...
Read more >
Custom Error Messages - express-validator
Custom Error Messages. express-validator's default error message is a simple Invalid value . That's enough to cover all fields without being too opinionated ......
Read more >
Providing custom error messages for built-in HTML5 form ...
How to customize built-in form validation error messages · Grab the input element(s) with a querySelector / querySelectorAll . · Add an event ......
Read more >
Custom Error Messages in a Form - Laserfiche Cloud
To configure a custom error message. In the form designer, navigate to the Error Messages tab. Under Display, type the error message that...
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