Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch 'MDL-35673-master' of git://git.luns.net.uk/moodle

  • Loading branch information...
commit 2aeb0fbb600be9ebdce23cdb5cd20d8a4b58497b 2 parents 001d5a0 + d6418e5
@stronk7 stronk7 authored
Showing with 18 additions and 10 deletions.
  1. +18 −10 lib/yui/formchangechecker/formchangechecker.js
View
28 lib/yui/formchangechecker/formchangechecker.js
@@ -11,6 +11,10 @@ YUI.add('moodle-core-formchangechecker',
}
Y.extend(FORMCHANGECHECKER, Y.Base, {
+
+ // The delegated listeners we need to detach after the initial value has been stored once
+ initialvaluelisteners : [],
+
/**
* Initialize the module
*/
@@ -18,14 +22,15 @@ YUI.add('moodle-core-formchangechecker',
var formid = 'form#' + this.get('formid');
// Add change events to the form elements
- Y.all(formid + ' input').once('change', M.core_formchangechecker.set_form_changed, this);
- Y.all(formid + ' textarea').once('change', M.core_formchangechecker.set_form_changed, this);
- Y.all(formid + ' select').once('change', M.core_formchangechecker.set_form_changed, this);
+ var currentform = Y.one(formid);
+ currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'input', this);
+ currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'textarea', this);
+ currentform.delegate('change', M.core_formchangechecker.set_form_changed, 'select', this);
// Add a focus event to check for changes which are made without triggering a change event
- Y.all(formid + ' input').on('focus', this.store_initial_value, this);
- Y.all(formid + ' textarea').on('focus', this.store_initial_value, this);
- Y.all(formid + ' select').on('focus', this.store_initial_value, this);
+ this.initialvaluelisteners.push(currentform.delegate('focus', this.store_initial_value, 'input', this));
+ this.initialvaluelisteners.push(currentform.delegate('focus', this.store_initial_value, 'textarea', this));
+ this.initialvaluelisteners.push(currentform.delegate('focus', this.store_initial_value, 'select', this));
// We need any submit buttons on the form to set the submitted flag
Y.one(formid).on('submit', M.core_formchangechecker.set_form_submitted, this);
@@ -52,9 +57,12 @@ YUI.add('moodle-core-formchangechecker',
// we no longer need to call this function
var formid = 'form#' + this.get('formid');
- Y.all(formid + ' input').detach('focus', this.store_initial_value, this);
- Y.all(formid + ' textarea').detach('focus', this.store_initial_value, this);
- Y.all(formid + ' select').detach('focus', this.store_initial_value, this);
+ // Detach all listen events to prevent duplicate initial value setting
+ var thisevent;
+ while (thisevent = this.initialvaluelisteners.shift()) {
+ thisevent.detach();
+ }
+
return;
}
@@ -176,6 +184,6 @@ YUI.add('moodle-core-formchangechecker',
};
},
'@VERSION@', {
- requires : ['base']
+ requires : ['base', 'event-focus']
}
);
Please sign in to comment.
Something went wrong with that request. Please try again.