-
Notifications
You must be signed in to change notification settings - Fork 17
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
Fix registration code form button from disabling on invalid entry and… #342
base: master
Are you sure you want to change the base?
Conversation
… retry: Issue #309 The problem was code disabling the button right away rather than waiting and disabling it after the form is validated to prevent multiple submissions Add type='submit' to form submit button. For the submitHandler in the Jquery Validation Plugin to get called, it requires a button inside the form with the type='submit'. Add code to return JSON format of python True or False value in implementation.py In the implementation.py file, the function get_ajax_check_ffq_code validates the form entry, and it needs to return a JSON value of true or false since it is returning the value to a JavaScript function that doesn't understand python True or False. This function was changed to return JSON of a True or False value. Put the submitHandler of the validator outside the 'rules' object in order for it to be called. Test using a return value of True and False in the function get_ajax_check_ffq_code in the implementation.py file to call the submit handler function. Now the submit handler is called on a returned True value and the message of an invalid key is displayed on a returned False value. Add comment in submit handler function to create a function call in the submit handler which is empty.
}); | ||
function handleSubmit() { | ||
// TODO go to page since form validated | ||
console.log('submitted form') |
There was a problem hiding this comment.
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.
document.getElementById("ffq_code_button").disabled = true; | ||
}); | ||
function handleSubmit() { | ||
// TODO go to page since form validated |
There was a problem hiding this comment.
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.
submitHandler: function (form, event) { | ||
// prevent multiple submissions | ||
document.getElementById("ffq_code_button").disabled = false; | ||
handleSubmit(form); |
There was a problem hiding this comment.
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?
I'll consolidate the code into the plugin submit handler and remove the console.log. But there was no functionality in the form submit to begin with. The original on submit code is strange because it doesn't do anything once the form is submitted. It just disables the button.
And you're right, this on submit function is extra if there is a submit handler used by the jQuery validation plugin since the code inside of it can be placed in the plugin handler. The on submit function The jQuery validation submit handler So this the plugin submit handler should be
And then nothing is done except disabling the button And yep, I should have removed the console.log function. So the code doesn't break anything because nothing was done before my code changes were made. |
…in code Remove debugging statement
That's inaccurate. I would encourage you to do the following:
I just confirmed this behavior on both my laptop and our staging server, so if the behavior differs in your local environment, I'd be very curious to see it. |
OK, I’ll do that. I guess I wasn’t clear with what the code was doing. Thanks for pointing it out in more detail.
Lynne
Lynne Merchant
CMI Information Systems Analyst
Center for Microbiome Innovation
Jacobs School of Engineering University of California San Diego
… On Feb 14, 2025, at 2:08 PM, Cassidy Symons ***@***.***> wrote:
cassidysymons
left a comment
(biocore/microsetta-interface#342)
So the code doesn't break anything because nothing was done before my code changes were made.
That's inaccurate. I would encourage you to do the following:
Switch your local microsetta-interface branch to master.
Login using admin credentials, navigate to Admin Tools > FFQ Codes, and hit the "Generate" button next to "Generate Single Code."
Login using normal user credentials and use the FFQ code that was generated in step 2. The code will be deemed valid and the page will reload with a "Begin FFQ" button (you won't be able to actually open the FFQ, but that's irrelevant).
I just confirmed this behavior on both my laptop and our staging server, so if the behavior differs in your local environment, I'd be very curious to see it.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.
<https://urldefense.com/v3/__https://github.com/biocore/microsetta-interface/pull/342*issuecomment-2660360867__;Iw!!Mih3wA!A3lzdJQYp8y3RnAYsPEfDY5tIIzCz5-GLQ11r8fNIMYOo-8drRf5oeLxkN-nzLgmy-q9BXCt-9xTq_MSln__1Jds1Q$> <https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AEYDTUSEB5EOUSNC4HB2EDT2PZSPRAVCNFSM6AAAAABXFDODOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRQGM3DAOBWG4__;!!Mih3wA!A3lzdJQYp8y3RnAYsPEfDY5tIIzCz5-GLQ11r8fNIMYOo-8drRf5oeLxkN-nzLgmy-q9BXCt-9xTq_MSln_-sL86jA$>
cassidysymons
left a comment
(biocore/microsetta-interface#342)
<https://urldefense.com/v3/__https://github.com/biocore/microsetta-interface/pull/342*issuecomment-2660360867__;Iw!!Mih3wA!A3lzdJQYp8y3RnAYsPEfDY5tIIzCz5-GLQ11r8fNIMYOo-8drRf5oeLxkN-nzLgmy-q9BXCt-9xTq_MSln__1Jds1Q$>
So the code doesn't break anything because nothing was done before my code changes were made.
That's inaccurate. I would encourage you to do the following:
Switch your local microsetta-interface branch to master.
Login using admin credentials, navigate to Admin Tools > FFQ Codes, and hit the "Generate" button next to "Generate Single Code."
Login using normal user credentials and use the FFQ code that was generated in step 2. The code will be deemed valid and the page will reload with a "Begin FFQ" button (you won't be able to actually open the FFQ, but that's irrelevant).
I just confirmed this behavior on both my laptop and our staging server, so if the behavior differs in your local environment, I'd be very curious to see it.
—
Reply to this email directly, view it on GitHub <https://urldefense.com/v3/__https://github.com/biocore/microsetta-interface/pull/342*issuecomment-2660360867__;Iw!!Mih3wA!A3lzdJQYp8y3RnAYsPEfDY5tIIzCz5-GLQ11r8fNIMYOo-8drRf5oeLxkN-nzLgmy-q9BXCt-9xTq_MSln__1Jds1Q$>, or unsubscribe <https://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AEYDTUSEB5EOUSNC4HB2EDT2PZSPRAVCNFSM6AAAAABXFDODOOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMNRQGM3DAOBWG4__;!!Mih3wA!A3lzdJQYp8y3RnAYsPEfDY5tIIzCz5-GLQ11r8fNIMYOo-8drRf5oeLxkN-nzLgmy-q9BXCt-9xTq_MSln_-sL86jA$>.
You are receiving this because you authored the thread.
|
I added form.submit() to the jQuery validation plugin submit handler so that it will go ahead and call the POST action on the form. The issue of it breaking the page was due to an error in the SQL query in microsetta-private-api where it was checking that a valid registration code was NULL, but it should have been checking it was NOT NULL. I'll make a pull request for that fix. |
Remove extra code and add comments.
I removed the pull request to modify check FFQ code database search. The nutrition page now allows a user to enter a correct FFQ code and if not, will not disable the button to submit one. I also tested the code with jest to test various cases with a valid or invalid FFQ code. |
… retry: Issue #309
The problem was code disabling the button right away rather than waiting and disabling it after the form is validated to prevent multiple submissions
Add type='submit' to form submit button.
For the submitHandler in the Jquery Validation Plugin to get called, it requires a button inside the form with the type='submit'.
Add code to return JSON format of python True or False value in implementation.py In the implementation.py file, the function get_ajax_check_ffq_code validates the form entry, and it needs to return a JSON value of true or false since it is returning the value to a JavaScript function that doesn't understand python True or False. This function was changed to return JSON of a True or False value.
Put the submitHandler of the validator outside the 'rules' object in order for it to be called.
Test using a return value of True and False in the function get_ajax_check_ffq_code in the implementation.py file to call the submit handler function. Now the submit handler is called on a returned True value and the message of an invalid key is displayed on a returned False value.
Add comment in submit handler function to create a function call in the submit handler which is empty.