alleyinteractive / alleyinteractive/wordpress-fieldmanager

Term form validation

Đang mở
#515 1 bình luận 0 reaction 1 người được giao Được @mboynes nhận Xem trên GitHub
bug
Ngôn ngữ chính
PHP
Star
563
Fork
99
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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 ).

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.