3 function testInteractiveValidationRequired(config) {
4 description("Test interactive validation with required attribute. This test checks if an empty required field prevents form submission and checks if a non-empty required field doesn't prevent form submission.");
6 var expectedValue = config['expectedValue'];
8 var keyValuePairs = window.location.search.replace('?', '').split('&');
9 for (var index = 0; index < keyValuePairs.length; ++index) {
10 var keyValue = keyValuePairs[index].split('=');
11 queryValues[keyValue[0]] = unescape(keyValue[1]);
14 if (queryValues['submitted']) {
15 shouldBeEqualToString('queryValues["test"]', expectedValue);
20 var form = document.createElement("form");
21 form.setAttribute("action", window.location);
22 form.innerHTML = '<input type=hidden name=submitted value=1><input id=submit type=submit><input id=test name=test type=' + config['inputType'] + ' required>';
23 document.body.appendChild(form);
25 debug('Submit without required value');
26 document.getElementById('submit').click();
28 if (document.activeElement.id != 'test') {
29 testFailed('Focus should be on test element.');
34 debug('Submit with required value');
35 document.getElementById('test').value = expectedValue;
36 document.getElementById('submit').click();
37 setTimeout(function() {
38 // This is executed only if the test runs not as expected.
39 testFailed('The form was not submitted.');
45 wasPostTestScriptParsed = true;