horprogs / Just-validate

Modern, simple, lightweight (~5kb gzip) form validation library written in Typescript, with no dependencies (no JQuery!). Support a wide range of predefined rules, async, files, dates validation, custom error messages and styles, localization. Support writing custom rules and plugins.

Home Page:https://just-validate.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

My submit button is actually an input element

bezlashkari opened this issue · comments

Hello, I'm not sure if this is currently possible and I just don't know how to get it to work but I'm using this library for some Drupal 9 webform validation. Unfortunately the Drupal submit action is controlled by an input element and not a button.

Is there anyway I can get the Just Validate library to work with an input element for submission rather than a button?

Thanks,
Bez

Hi! The library catches submit event. Not sure how Drupal works, but I guess you could manually fire a submit event, like this:

           document.querySelector("#submit").addEventListener("click", () => {
              document.querySelector("#basic_form").requestSubmit();
            });

So you can use any element, click on that and then call a requestSubmit form method.

Created an example here https://codesandbox.io/s/just-validate-template-forked-v49lcv?file=/index.html