Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-28987 Forms Library: Added tinyMCE save for tinymce editor valida…

…tion
  • Loading branch information...
commit 98b8818735625e401e401cff6777238d16367918 1 parent 52ed7bb
Rajesh Taneja authored
Showing with 19 additions and 8 deletions.
  1. +16 −2 lib/form/editor.php
  2. +3 −6 lib/formslib.php
View
18 lib/form/editor.php
@@ -86,6 +86,15 @@ function setSubdirs($allow) {
$this->_options['subdirs'] = $allow;
}
+ /**
+ * Checks if editor used is tinymce and is required field
+ *
+ * @return true if required field.
+ */
+ function isRequiredTinymce() {
+ return (isset($this->_options['required_tinymce']) && $this->_options['required_tinymce']);
+ }
+
function setHelpButton($_helpbuttonargs, $function='_helpbutton') {
if (!is_array($_helpbuttonargs)) {
$_helpbuttonargs = array($_helpbuttonargs);
@@ -198,16 +207,21 @@ function toHtml() {
$fpoptions['link'] = $link_options;
}
+ //If editor is required and tinymce, then set required_tinymce option to initalize tinymce validation.
+ if (($editor instanceof tinymce_texteditor) && !is_null($this->getAttribute('onchange'))) {
+ $this->_options['required_tinymce'] = true;
+ }
+
/// print text area - TODO: add on-the-fly switching, size configuration, etc.
$editor->use_editor($id, $this->_options, $fpoptions);
$rows = empty($this->_attributes['rows']) ? 15 : $this->_attributes['rows'];
$cols = empty($this->_attributes['cols']) ? 80 : $this->_attributes['cols'];
- //Apply editor rules is required
+ //Apply editor validation if required field
$editorrules = '';
if (!is_null($this->getAttribute('onblur')) && !is_null($this->getAttribute('onchange'))) {
- $editorrules = 'onblur="'.$this->getAttribute('onblur').'" onchange="'.$this->getAttribute('onchange').'"';
+ $editorrules = 'onblur="'.$this->getAttribute('onblur').'" onchange="'.$this->getAttribute('onchange').'"';
}
$str .= '<div><textarea id="'.$id.'" name="'.$elname.'[text]" rows="'.$rows.'" cols="'.$cols.'"'.$editorrules.'>';
$str .= s($text);
View
9 lib/formslib.php
@@ -1767,12 +1767,9 @@ function qf_errorHandler(element, _qfMsg) {
'/[_\[\]]/',
create_function('$matches', 'return sprintf("_%2x",ord($matches[0]));'),
$elementName);
- if ($element->_type == 'editor') {
- $tinyjs = "
- if (tinyMCE.get('id_{$element->getName()}')) {
- tinyMCE.get('id_{$element->getName()}').save();
- }";
- array_unshift($jsArr, $tinyjs);
+ //If editor is tinymce then tinymce should save contents before textarea can be validated.
+ if (($element->_type == 'editor') && $element->isRequiredTinymce()) {
+ array_unshift($jsArr, "tinyMCE.get('{$element->getAttribute('id')}').save();");
}
$js .= '
function validate_' . $this->_formName . '_' . $escapedElementName . '(element) {
Please sign in to comment.
Something went wrong with that request. Please try again.