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 all commits
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
26 changes: 14 additions & 12 deletions microsetta_interface/templates/nutrition.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,29 @@
preventImplicitSubmission(form_name);
preclude_whitespace('#ffq_code');

$("form[name='" + form_name + "']").on('submit', function() {
document.getElementById("ffq_code_button").disabled = true;
});

// Initialize form validation on the registration form.
// It has the name attribute "registration"
// Validate the FFQ code registration form using
// the jQuery validation plugin.
$("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
// The key name on the left side is the
// name attribute of an input field.
// Validation rules are defined
// on the right side
// the remote get ajax call needs to
// return the string "true" for the
// form to validate and submit
ffq_code: {
required: true,
remote: {
url: "/check_ffq_code_valid",
}
},
submitHandler: function (form) {
form.submit();
}
},
submitHandler: function (form) {
// prevent multiple submissions
document.getElementById("ffq_code_button").disabled = true;
form.submit()
},
messages: {
ffq_code: "{{ _('Your registration code is not in our system or has already been used. Please try again.') }}",
Expand Down Expand Up @@ -216,7 +218,7 @@
</div>
</div>
<div class="col-12 text-center mt-4">
<button class="btn btn-blue-gradient" name="ffq_code_button" id="ffq_code_button">{{ _('Register FFQ') }}</button>
<button type='submit' class="btn btn-blue-gradient" name="ffq_code_button" id="ffq_code_button">{{ _('Register FFQ') }}</button>
</div>
</div>
</div>
Expand Down