I have installed clientside validation contributed module in my Drupal 8 Project. Now all client side validations are looking uniformed throughout the site.

The only issue I am facing right now is about overriding Default error messages.

I have googled about how to override but everywhere I am getting suggestion of removing #required = true from the field definition and then in form_validate I can set error message with the help of form_error_message like below:

$name = $form_state->getValue('name');
if (empty($name)) {
   $form_state->setErrorByName('name', $this->t('Email is required.'));

But is there any way to just override error message without removing required true & writing obvious logic once again like if ( empty(field) ) then set custom error message.

Please provide if any other way than above

  • Please provide if any other way than above JS :p – No Sssweat Jan 24 at 11:46
  • My site is multi-lingual, how to manage that if I use JS? @NoSssweat – Akki Jan 24 at 13:48
  • try this answer – No Sssweat Jan 25 at 0:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.