sha256 / Pristine

Vanilla javascript form validation micro-library
https://pristine.js.org/
MIT License
410 stars 81 forks source link

[1.0.0] Required errors messages are no longer injected #91

Closed msev closed 1 year ago

msev commented 1 year ago

Hi @sha256

Since version 1.0.0, All errors messages are properly injected except for the required one.

Can you check please ?

sha256 commented 1 year ago

Can you give me an example to check? I can see that it works properly here: https://codepen.io/sha256/pen/JezmLp

msev commented 1 year ago

Sorry for not being precise.

It's related to addValidator

Before 1.0.0, data-pristine-required-message was stronger than the message in addValidator, this is no longer valid since version 1.0.0.

Pristine.addValidator(
  'required',
  function(value) {
    if (this.type === 'radio' || this.type === 'checkbox') {
      return this.pristine.self.form.querySelector('[name="' + this.name + '"]:checked');
    } else {
      return value.trim() !== '';
    }
  },
  '',
  1,
  true
);
msev commented 1 year ago

Change the line '' to false solves my problem

Pristine.addValidator(
  'required',
  function(value) {
    if (this.type === 'radio' || this.type === 'checkbox') {
      return this.pristine.self.form.querySelector('[name="' + this.name + '"]:checked');
    } else {
      return value.trim() !== '';
    }
  },
  false, <----- this line
  1,
  true
);

Sorry to have wasted your time and thank you for keeping this library alive!