0

I have added custom fields to a custom taxonomy, but I think this would apply equally if someone is searching later for the same solution with a default field.

My challenge is to stop the adding of a term if a certain field is blank and pop up an explanation of why I blocked the term from being added.

I tried:

(function( $ ) {
    $( document ).on( 'submit', '#addtag', function( e ) {
        // Block addition. Add notice.
    });
})( jQuery );

The problem is that WordPress has a function firing on submit that stores the new term via ajax. It returns false even if successful so my code never runs.

Any ideas on how to make my code run first or other ways to make sure that field is not empty?

0

Turns out the easiest solution is to add 'form-required' to the class of the <div> wrapping the <input> you want to require. Then if you want to add an alert to let the user know what happened you can trigger that on mouseup on the button instead of submit on the form.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.