MDL-22414 Fixed the id generation entropy
[moodle.git] / question / qengine.js
blob36bf82cb09af65a36aed0233b53e9d3acccca589
1 M.core_question_engine = M.core_question_engine || {};
3 /**
4  * Initialise a form that contains questions printed using print_question.
5  * This has the effect of:
6  * 1. Turning off browser autocomlete.
7  * 2. Stopping enter from submitting the form (or toggling the next flag) unless
8  *    keyboard focus is on the submit button or the flag.
9  * 3. Removes any '.questionflagsavebutton's, since we have JavaScript to toggle
10  *    the flags using Ajax.
11  * @param Y the Yahoo object. Needs to have the DOM and Event modules loaded.
12  * @param form something that can be passed to Y.one, to find the form element.
13  */
14 M.core_question_engine.init_form = function(Y, form) {
15     Y.one(form).setAttribute('autocomplete', 'off');
16     Y.on('key', function (e) {
17         if (!e.target.test('a') && !e.target.test('input[type=submit]') &&
18                 !e.target.test('input[type=img]') && !e.target.test('textarea')) {
19             e.preventDefault();
20         }
21     }, form, 'press:13');
22     Y.one(form).all('.questionflagsavebutton').remove();