Skip to content

Commit 0ff3b3c

Browse files
staabmjzaefferer
authored andcommitted
Demo: Added a tinymce4 demo
Closes jquery-validation#1340
1 parent 4d8ccab commit 0ff3b3c

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

demo/index.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,9 @@ <h3>Synthetic examples</h3>
209209
</li>
210210
<li><a href="themerollered.html">Forms styled with jQuery UI Themeroller</a>
211211
</li>
212-
<li><a href="tinymce/">TinyMCE Demo</a>
212+
<li><a href="tinymce/">TinyMCE3 Demo</a>
213+
</li>
214+
<li><a href="tinymce4/">TinyMCE4 Demo</a>
213215
</li>
214216
<li><a href="file_input.html">File inputs</a>
215217
</li>

demo/tinymce4/index.html

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>jQuery Validation plugin: integration with TinyMCE</title>
6+
<script src="../../lib/jquery.js"></script>
7+
<script src="../../dist/jquery.validate.js"></script>
8+
<script src="//tinymce.cachefly.net/4.1/tinymce.min.js"></script>
9+
<script>
10+
tinymce.init({
11+
mode: "textareas",
12+
13+
setup: function(editor) {
14+
editor.on('change', function(e) {
15+
tinymce.triggerSave();
16+
$("#" + editor.id).valid();
17+
});
18+
}
19+
20+
});
21+
$(function() {
22+
var validator = $("#myform").submit(function() {
23+
// update underlying textarea before submit validation
24+
tinyMCE.triggerSave();
25+
}).validate({
26+
ignore: "",
27+
rules: {
28+
title: "required",
29+
content: "required"
30+
},
31+
errorPlacement: function(label, element) {
32+
// position error label after generated textarea
33+
if (element.is("textarea")) {
34+
label.insertAfter(element.next());
35+
} else {
36+
label.insertAfter(element)
37+
}
38+
}
39+
});
40+
validator.focusInvalid = function() {
41+
// put focus on tinymce on submit validation
42+
if (this.settings.focusInvalid) {
43+
try {
44+
var toFocus = $(this.findLastActive() || this.errorList.length && this.errorList[0].element || []);
45+
if (toFocus.is("textarea")) {
46+
tinyMCE.get(toFocus.attr("id")).focus();
47+
} else {
48+
toFocus.filter(":visible").focus();
49+
}
50+
} catch (e) {
51+
// ignore IE throwing errors when focusing hidden elements
52+
}
53+
}
54+
}
55+
})
56+
</script>
57+
<!-- /TinyMCE -->
58+
</head>
59+
<body>
60+
<form id="myform" action="">
61+
<h3>TinyMCE4 and Validation Plugin integration example</h3>
62+
<label>Some other field</label>
63+
<input name="title">
64+
<br>
65+
<label>Some richt text</label>
66+
<textarea id="content" name="content" rows="15" cols="80" style="width: 80%"></textarea>
67+
<br>
68+
<input type="submit" name="save" value="Submit">
69+
</form>
70+
</body>
71+
</html>

0 commit comments

Comments
 (0)