form.delegate('click', this.switch_state, SELECTORS.FIELDSETLEGENDLINK, this);
form.delegate('key', this.switch_state, 'down:enter,32', SELECTORS.FIELDSETLEGENDLINK, this);
+ // Handle event, when there's an error in collapsed section.
+ Y.Global.on(M.core.globalEvents.FORM_ERROR, this.expand_fieldset, this);
+
// Make the collapse/expand a link.
btn = form.one(SELECTORS.COLLAPSEEXPAND);
if (btn) {
}
return this;
- }
+ },
+ /**
+ * Expand the fieldset, which contains an error.
+ *
+ * @method expand_fieldset
+ * @param {EventFacade} e
+ */
+ expand_fieldset: function(e) {
+ e.stopPropagation();
+ var formid = e.formid;
+ if (formid === this.form.getAttribute('id')) {
+ var errorfieldset = Y.one('#' + e.elementid).ancestor('fieldset');
+ if (errorfieldset) {
+ this.set_state(errorfieldset, false);
+ }
+
+ }
+ }
}, {
NAME: 'moodle-form-shortforms',
ATTRS: ATTRS
ret = validate_' . $this->_formName . '_' . $escapedElementName.'(frm.elements[\''.$elementName.'\']) && ret;
if (!ret && !first_focus) {
first_focus = true;
+ Y.Global.fire(M.core.globalEvents.FORM_ERROR, {formid: \''. $this->_attributes['id'] .'\',
+ elementid: \'id_error_'.$elementName.'\'});
document.getElementById(\'id_error_'.$elementName.'\').focus();
}
';
FILTER_CONTENT_UPDATED: "filter-content-updated"
};
+M.core.globalEvents = {
+ /**
+ * This event is triggered when form has an error
+ *
+ * @event "form_error"
+ * @param formid {string} Id of form with error.
+ * @param elementid {string} Id of element with error.
+ */
+ FORM_ERROR: "form_error"
+};
+
var eventDefaultConfig = {
emitFacade: true,
}
};
+// Publish events with a custom config here.
+
// Publish all the events with a standard config.
var key;
for (key in M.core.event) {
}
}
-// Publish events with a custom config here.
+//Publish all the 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}));
+ }
+}