MDL-20636 todo list
[moodle.git] / question / qengine.js
CommitLineData
157434a5
TH
1M.core_question_engine = M.core_question_engine || {};
2
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 */
14M.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]')) {
19 e.preventDefault();
20 }
21 }, form, 'press:13');
22 Y.one(form).all('.questionflagsavebutton').remove();
23}