Skip to content

Commit

Permalink
MDL-50852 formslib: Fixed client-side form validation problem.
Browse files Browse the repository at this point in the history
This patch fixes the problem of client validation being broken when
shortforms is not enabled. This issue is caused by moodle-core-event
module not being loaded and the broadcast parameter in the
Y.Global.publish set to 2 instead of true.
  • Loading branch information
junpataleta committed Sep 9, 2015
1 parent 1dabede commit 36e0030
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
8 changes: 5 additions & 3 deletions lib/formslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2233,9 +2233,11 @@ function validate_' . $this->_formName . '_' . $escapedElementName . '(element,
ret = validate_' . $this->_formName . '_' . $escapedElementName.'(frm.elements[\''.$elementName.'\'], \''.$escapedElementName.'\') && ret;
if (!ret && !first_focus) {
first_focus = true;
Y.Global.fire(M.core.globalEvents.FORM_ERROR, {formid: \''. $this->_attributes['id'] .'\',
elementid: \'id_error_'.$escapedElementName.'\'});
document.getElementById(\'id_error_'.$escapedElementName.'\').focus();
Y.use(\'moodle-core-event\', function() {
Y.Global.fire(M.core.globalEvents.FORM_ERROR, {formid: \'' . $this->_attributes['id'] . '\',
elementid: \'id_error_' . $escapedElementName . '\'});
document.getElementById(\'id_error_' . $escapedElementName . '\').focus();
});
}
';

Expand Down
14 changes: 8 additions & 6 deletions lib/yui/build/moodle-core-event/moodle-core-event-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var LOGNAME = 'moodle-core-event';
*/
M.core = M.core || {};

M.core.event = {
M.core.event = M.core.event || {
/**
* This event is triggered when a page has added dynamic nodes to a page
* that should be processed by the filter system. An example is loading
Expand All @@ -44,7 +44,7 @@ M.core.event = {
FILTER_CONTENT_UPDATED: "filter-content-updated"
};

M.core.globalEvents = {
M.core.globalEvents = M.core.globalEvents || {
/**
* This event is triggered when form has an error
*
Expand Down Expand Up @@ -74,15 +74,17 @@ var eventDefaultConfig = {
// Publish all the events with a standard config.
var key;
for (key in M.core.event) {
if (M.core.event.hasOwnProperty(key)) {
if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) {
Y.publish(M.core.event[key], eventDefaultConfig);
}
}

//Publish all the global events.
// Publish global events.
for (key in M.core.globalEvents) {
if (M.core.globalEvents.hasOwnProperty(key)) {
Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: 2}));
// Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing.
if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) {
Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true}));
Y.log('Global event published: ' + key, 'debug', LOGNAME);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/yui/build/moodle-core-event/moodle-core-event-min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 7 additions & 6 deletions lib/yui/build/moodle-core-event/moodle-core-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var LOGNAME = 'moodle-core-event';
*/
M.core = M.core || {};

M.core.event = {
M.core.event = M.core.event || {
/**
* This event is triggered when a page has added dynamic nodes to a page
* that should be processed by the filter system. An example is loading
Expand All @@ -44,7 +44,7 @@ M.core.event = {
FILTER_CONTENT_UPDATED: "filter-content-updated"
};

M.core.globalEvents = {
M.core.globalEvents = M.core.globalEvents || {
/**
* This event is triggered when form has an error
*
Expand All @@ -71,15 +71,16 @@ var eventDefaultConfig = {
// Publish all the events with a standard config.
var key;
for (key in M.core.event) {
if (M.core.event.hasOwnProperty(key)) {
if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) {
Y.publish(M.core.event[key], eventDefaultConfig);
}
}

//Publish all the global events.
// Publish global events.
for (key in M.core.globalEvents) {
if (M.core.globalEvents.hasOwnProperty(key)) {
Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: 2}));
// Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing.
if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) {
Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true}));
}
}

Expand Down
14 changes: 8 additions & 6 deletions lib/yui/src/event/js/event.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var LOGNAME = 'moodle-core-event';
*/
M.core = M.core || {};

M.core.event = {
M.core.event = M.core.event || {
/**
* This event is triggered when a page has added dynamic nodes to a page
* that should be processed by the filter system. An example is loading
Expand All @@ -42,7 +42,7 @@ M.core.event = {
FILTER_CONTENT_UPDATED: "filter-content-updated"
};

M.core.globalEvents = {
M.core.globalEvents = M.core.globalEvents || {
/**
* This event is triggered when form has an error
*
Expand Down Expand Up @@ -72,14 +72,16 @@ var eventDefaultConfig = {
// Publish all the events with a standard config.
var key;
for (key in M.core.event) {
if (M.core.event.hasOwnProperty(key)) {
if (M.core.event.hasOwnProperty(key) && Y.getEvent(M.core.event[key]) === null) {
Y.publish(M.core.event[key], eventDefaultConfig);
}
}

//Publish all the global events.
// Publish global events.
for (key in M.core.globalEvents) {
if (M.core.globalEvents.hasOwnProperty(key)) {
Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: 2}));
// Make sure the key exists and that the event has not yet been published. Otherwise, skip publishing.
if (M.core.globalEvents.hasOwnProperty(key) && Y.Global.getEvent(M.core.globalEvents[key]) === null) {
Y.Global.publish(M.core.globalEvents[key], Y.merge(eventDefaultConfig, {broadcast: true}));
Y.log('Global event published: ' + key, 'debug', LOGNAME);
}
}

0 comments on commit 36e0030

Please sign in to comment.