alleyinteractive / alleyinteractive/wordpress-fieldmanager

Term form validation

Aperta
#515 1 commento 0 reazioni 1 assegnatario Rivendicata da @mboynes Vedi su GitHub
bug
Lingua principale
PHP
Stelle
563
Fork
99
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Term form validation is broken, because how Core is doing the submission in term list ( add form ) page.

jQuery Validation apparently [should hook](https://github.com/jzaefferer/jquery-validation/blob/master/src/core.js#L28) on `click` event for `:submit` input within the form, but somehow that does not get bound ( inspecting `$form.data('events').click` didn't show any entry from jQuery.validation ), and I didn't trace the reason for that.

**Steps to reproduce**
- Add a select or a textarea input in term
- Mark it as required, using either/both `required` and `validation_rules` params ( a bit confused on why `required` isn't working but `validation_rules` is for term edit pages, which works fine ).
- Submit the form without filling the new inputs

**Expected**
- Form is not submitted and error messages is present

**Actual**
- No errors, and the form is submitted

**Proposed Solution**
- Overload the validateForm function to execute jQuery validation first. Something in the lines of

``` js
let body = $( 'body' );
if ( body.hasClass( 'edit-tags-php' ) || body.hasClass( 'term-php' ) ) {
if ( 'undefined' !== typeof validateForm ) {
var wpValidateForm = validateForm;
validateForm = function( form ) {
return ! ( ! wpValidateForm( form ) || ( 'undefined' !== typeof $( form ).data().validator && ! $( form ).data().validator.form() ) );
};
}
}
```

**Note**
- This is a bit related to this Trac ticket: https://core.trac.wordpress.org/ticket/37540, so would not have been discovered without Core failing in that ( because I'm mainly using the required validation rule only ). But would've still be an issue for other validation rules ( which validateForm does not handle ).

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.