Skip to content

Fix registration code form button from disabling on invalid entry and… #342

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion microsetta_interface/implementation.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,7 +874,8 @@ def get_ajax_check_ffq_code(ffq_code):
except: # noqa
return_val = False

return return_val
# Convert to JSON for returning to JavaScript call
return json.dumps(return_val)


def _associate_sample_to_survey(account_id, source_id, sample_id, survey_id):
Expand Down
38 changes: 17 additions & 21 deletions microsetta_interface/templates/nutrition.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -44,43 +44,39 @@
preventImplicitSubmission(form_name);
preclude_whitespace('#ffq_code');

$("form[name='" + form_name + "']").on('submit', function() {
document.getElementById("ffq_code_button").disabled = true;
});
function handleSubmit() {
// TODO go to page since form validated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be addressed before we can consider merging the pull request. As it stands, this PR breaks the functionality for the tool.

console.log('submitted form')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make sure to remove debug info before opening pull requests.

};

// Initialize form validation on the registration form.
// It has the name attribute "registration"
// Validate the registration form for a valid
// registration code using the jQuery validation plugin.
// If the form is not valid, the messages are displayed
$("form[name='" + form_name + "']").validate({
// Specify validation rules
rules: {
// The key name on the left side is the name attribute
// of an input field. Validation rules are defined
// on the right side
// The key is the form input field name attribute and the validation rules
// are defined in the value object
// The route check_ffq_code_valid returns
// either true or false
ffq_code: {
required: true,
remote: {
url: "/check_ffq_code_valid",
}
},
submitHandler: function (form) {
form.submit();
}
},
submitHandler: function (form, event) {
// prevent multiple submissions
document.getElementById("ffq_code_button").disabled = false;
handleSubmit(form);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is a helper function necessary here?

},
messages: {
ffq_code: "{{ _('Your registration code is not in our system or has already been used. Please try again.') }}",
},
});
});

/*
function updateButtonState(ffq_code_value) {
if(ffq_code_value != "") {
document.getElementById("ffq_code_button").disabled = false;
} else {
document.getElementById("ffq_code_button").disabled = true;
}
}
*/
});

function openCodePanel() {
document.getElementById('add_code_container').style.display = '';
Expand Down