Skip to content

Commit

Permalink
Modify preventImplicitSubmission to apply to select elements as well …
Browse files Browse the repository at this point in the history
…as input elements

Disable all input elements once "submit survey" button is clicked
  • Loading branch information
AmandaBirmingham committed Jun 16, 2020
1 parent 78c6f89 commit 3bc7ff1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
20 changes: 11 additions & 9 deletions microsetta_private_api/static/input_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ function preclude_whitespace(selector) {
// standards for accessibility purposes, it is causing confusion
// and premature form submission for our user base
function preventImplicitSubmission(form_name){
let implicit_sub_input_types = ["text", "search", "url", "tel", "email", "password", "date", "month", "week", "time",
"datetime-local", "number"];
let partial_selector = 'form[name ="' + form_name + '"] input[type="';
// disable enter for all input elements that are not of type submit, button, or reset
// and for all select elements, that are found to occur at any level within the form.
// Note that enter is not disabled for textarea elements
let implicit_sub_input_types = ["input[type!='submit'][type!='button'][type!='reset']",
"select"];
let partial_selector = 'form[name ="' + form_name + '"]';
$.each(implicit_sub_input_types, function(index, value) {
let input_elements = $(partial_selector + value + '"]');
let input_elements = $(partial_selector).find(value);

// for each input element of the given type in form, disable submit on pressing Enter
// by making the keydown event return false on presses of that key
Expand All @@ -31,11 +34,10 @@ function preventImplicitSubmission(form_name){
});
}

function replicate_text(input_selector, destination_selector)
{
function replicate_text(input_selector, destination_selector) {
$(input_selector).bind('input', function(){
$(this).val(function(_, v){
$(destination_selector).html(v)
$(destination_selector).html(v);
return v
});
});
Expand All @@ -44,8 +46,8 @@ function replicate_text(input_selector, destination_selector)
function select_class(input_selector, destination_selector, input_to_class) {
$(input_selector).change(function(){
$(this).val(function(_, v){
$(destination_selector).removeClass()
$(destination_selector).addClass(input_to_class(v))
$(destination_selector).removeClass();
$(destination_selector).addClass(input_to_class(v));
return v
});
});
Expand Down
1 change: 1 addition & 0 deletions microsetta_private_api/templates/survey.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
type: "submit",
validateBeforeSubmit: true,
onSubmit: function(){
$("input").prop('disabled', true);
return postSurvey();
}
});
Expand Down

0 comments on commit 3bc7ff1

Please sign in to comment.