Required field
-
I am trying to set a field to required and just realized that WordPress ignores the default html field required functionality. Then I found the snippet to resolve this: https://github.com/CMB2/CMB2-Snippet-Library/blob/master/javascript/cmb2-js-validation-required.php.
I am using CMB2 from inside a small plugin I created. It’s working fine. So I put the snippet file inside my plugin folder, together with the cmb2-functions.php file, and included the cmb2-js-validation-required.php into cmb2-functions.php. Checked the HTML source, and saw the jquery code there. The attribute data-validation=”required” is added correclty to the field. All seem to be fine. But the required still not working.
What am I doing wrong?
There is a line in the snippet that gets the form element by id:
$form = $( document.getElementById( 'post' ) );
. There is no element with the id ‘post’. Should I change this id to something else? Or the problem lies somewhere else?Thanks!
- The topic ‘Required field’ is closed to new replies.