From 6786f79ab47caeb98c086074aba45ac4000c4e4b Mon Sep 17 00:00:00 2001 From: Rajesh Taneja Date: Wed, 31 Aug 2011 14:08:46 +0800 Subject: [PATCH] MDL-28987 Forms Library: Added tinyMCE save for tinymce editor validation --- lib/form/editor.php | 18 ++++++++++++++++-- lib/formslib.php | 9 +++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/form/editor.php b/lib/form/editor.php index fa2737c2dd7..677571f29b9 100644 --- a/lib/form/editor.php +++ b/lib/form/editor.php @@ -86,6 +86,15 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element { $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 @@ class MoodleQuickForm_editor extends HTML_QuickForm_element { $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 .= '