mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-28987 Forms Library: Added tinyMCE onblur event callback for required tinymce fields
This commit is contained in:
parent
cbe20ec362
commit
ab978b38c4
4 changed files with 57 additions and 18 deletions
|
@ -1710,11 +1710,16 @@ class MoodleQuickForm extends HTML_QuickForm_DHTMLRulesTableless {
|
|||
}
|
||||
}
|
||||
}
|
||||
// Fix for bug displaying errors for elements in a group
|
||||
//$test[$elementName][] = $registry->getValidationScript($element, $elementName, $rule);
|
||||
if ($element->_type == 'editor') {
|
||||
//for editor element, [text] is appended to the name.
|
||||
if ($element->getType() == 'editor') {
|
||||
$elementName .= '[text]';
|
||||
//Add format to rule as moodleform check which format is supported by browser
|
||||
//it is not set anywhere... So small hack to make sure we pass it down to quickform
|
||||
if (is_null($rule['format'])) {
|
||||
$rule['format'] = $element->getFormat();
|
||||
}
|
||||
}
|
||||
// Fix for bug displaying errors for elements in a group
|
||||
$test[$elementName][0][] = $registry->getValidationScript($element, $elementName, $rule);
|
||||
$test[$elementName][1]=$element;
|
||||
//end of fix
|
||||
|
@ -1787,10 +1792,6 @@ function qf_errorHandler(element, _qfMsg) {
|
|||
'/[_\[\]]/',
|
||||
create_function('$matches', 'return sprintf("_%2x",ord($matches[0]));'),
|
||||
$elementName);
|
||||
//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) {
|
||||
if (undefined == element) {
|
||||
|
@ -2401,17 +2402,18 @@ class MoodleQuickForm_Rule_Required extends HTML_QuickForm_Rule {
|
|||
/**
|
||||
* This function returns Javascript code used to build client-side validation.
|
||||
* It checks if an element is not empty.
|
||||
* Note, that QuickForm does not know how to work with editor text field and builds not correct
|
||||
* JS code for validation. If client check is enabled for editor field it will not be validated
|
||||
* on client side no matter what this function returns.
|
||||
*
|
||||
* @param mixed $options Not used yet
|
||||
* @param int $format
|
||||
* @return array
|
||||
*/
|
||||
function getValidationScript($options = null) {
|
||||
function getValidationScript($format = null) {
|
||||
global $CFG;
|
||||
if (!empty($CFG->strictformsrequired)) {
|
||||
return array('', "{jsVar}.replace(/^\s+$/g, '') == ''");
|
||||
if (!empty($format) && $format == FORMAT_HTML) {
|
||||
return array('', "{jsVar}.replace(/(<[^img|hr|canvas]+>)| |\s+/ig, '') == ''");
|
||||
} else {
|
||||
return array('', "{jsVar}.replace(/^\s+$/g, '') == ''");
|
||||
}
|
||||
} else {
|
||||
return array('', "{jsVar} == ''");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue