Для проверки формы я использую плагин JQuery Validation (jquery .validate. js) с дополнительными методами. js. Эта форма содержит множество входных данных, в которых отмечены поля, которые необходимо заполнить. Я использую правило onkeyup для полей. Все работает, но не работает правило onkeyup для tinymce. Что нужно прописать, чтобы заработало?
jQuery(function ($) {
var validator = $("#adminForm").submit(function() {
// update underlying textarea before submit validation
tinyMCE.triggerSave();
}).validate({
onkeyup: function(element) {
this.element(element); // <- "eager validation"
},
onfocusout: function(element) {
this.element(element); // <- "eager validation"
},
ignore: "",
rules: {
title: {
required: true,
minlength: 10,
maxlength: 50
},
donate: {
required: true,
digits: true,
min: 1,
max: 60000
},
text: {
required: true,
minlength: 250
},
checkbox: {
required: true
}
},
messages: {
title: {
required: "enter the title",
minlength: "no less than 10 symbols",
maxlength: "no more than 50 symbols"
},
donate: {
required: "enter the number",
digits: "Not a number",
min: "no less than 1",
max: "no more than 60000"
},
text: {
required: "here is your text",
minlength: "no less than 250 symbols"
},
checkbox: {
required: "do you public spam?"
}
},
errorPlacement: function(label, element) {
// position error label after generated textarea
if (element.is("textarea")) {
label.insertAfter(element.next());
} else {
label.insertAfter(element)
}
}
});
validator.focusInvalid = function() {
// put focus on tinymce on submit validation
if (this.settings.focusInvalid) {
try {
var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
if (toFocus.is("textarea")) {
tinyMCE.get(toFocus.attr("id")).focus();
} else {
toFocus.filter(":visible").focus();
}
} catch (e) {
// ignore IE throwing errors when focusing hidden elements
}
}
}
});