dockwa / simple-react-validator

A simple react form validator inspired by Laravel validation.
https://dockwa.github.io/simple-react-validator
MIT License
278 stars 78 forks source link

Custom Locale is not working. #427

Open prince17dec opened 2 years ago

prince17dec commented 2 years ago

When I try to use locale which the library supports, the locale is not working for example for English I got the proper message. "The username field is required." but in the case of another language "Fält :attribut krävs.'," basically here field name is missing which is username.

Am using the Swedish locale.

import SimpleReactValidator from 'simple-react-validator';
import 'simple-react-validator/dist/locale/sv';

const validator = useRef(new SimpleReactValidator({locale: 'sv'}));

<label>
  {t('username')}
  <input
      id="username"
      type="text"
      name="username"
      value={username}
      onChange={event => setUsername(event.target.value)}
      onBlur={()=>validator.current.showMessageFor('username')}
  />
  {validator.current.message('username', username, 'required|email')}
  </label>