2
I’m making a validate to be used in conjunction with tinymce. On the Jquery Validate website, there is an example to do this. There it works. My website is displaying the message "Uncaught Typeerror: Cannot set Property 'focusInvalid' of Undefined". I’ve touched everything and I can’t understand what happens.
Follow what I’ve done so far.
tinymce.init({
selector: "textarea",
fontsize_formats: "8pt 9pt 10pt 11pt 12pt 14pt 16pt 18pt 20pt 22pt 24pt 26pt 28pt 36pt 48pt 72pt",
theme: "modern",
height: 200,
resize: false,
language: "pt_BR",
removed_menuitems: 'newdocument',
forced_root_block : "",
force_br_newlines : true,
force_p_newlines : false,
plugins: [
"advlist autolink lists link image charmap preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code fullscreen",
"insertdatetime media nonbreaking save table contextmenu directionality",
"template paste textcolor colorpicker textpattern"
],
toolbar1: "insertfile undo redo | styleselect | fontsizeselect | bold italic | alignleft aligncenter alignright alignjustify",
toolbar2: "bullist numlist outdent indent | link image | print preview media | forecolor backcolor emoticons",
templates: [
{title: 'Test template 1', content: 'Test 1'},
{title: 'Test template 2', content: 'Test 2'}
]
});
$(function() {
var validator = $("#myform").submit(function() {
// update underlying textarea before submit validation
tinyMCE.triggerSave();
}).validate({
ignore: "",
rules: {
title: "required",
content: "required"
},
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
}
}
}
})
It is in this line "Validator.focusInvalid = Function() {" that gives the error.
You need to load the script from
validate
before running this code of yours. The error is happening because thevalidator
is an undefined variable at the time you are running this code.– Paulo Roberto Rosa
See that there’s a difference
tinymce.init
andtinyMCE
.– Sam