-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add warning on empty quiz response #1931
Conversation
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.
I gave your changes a first look and it's looking good. I left some syntax related suggestions as well as one question for now.
includes/template-functions.php
Outdated
|
||
$warn = get_post_meta( $sensei_question_loop[ 'quiz_id' ], '_warn_on_empty_response', true ); | ||
|
||
if ( ! empty( $warn ) ) |
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.
I think it's not necessarily a good practice to skip the curly braces - even for such short expressions.
You can also always use the shorthand notation which would be even better in this case:
return empty( $warn ) ? 'none' : 'warn';
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.
I think it's not necessarily a good practice to skip the curly braces - even for such short expressions.
Good point! Especially when using goto statements 😄
Changed to the ternary statement.
gulpfile.js
Outdated
.pipe( rename({ extname: '.min.js' }) ) | ||
.pipe( chmod( 644 ) ) | ||
.pipe( gulp.dest( 'assets/js/frontend' ) ); | ||
}); |
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.
Another potentially missing space between }
and )
.
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.
Fixed
gulpfile.js
Outdated
return gulp.src( paths.frontendScripts ) | ||
// This will minify and rename to *.min.js | ||
.pipe( uglify() ) | ||
.pipe( rename({ extname: '.min.js' }) ) |
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.
I think there should be spaces between all the braces here according to our JS style guidelines. Not sure if that applies here as well though ?
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.
Yeah good call. Most of this was copy+pasted, so I'll fix the spacing.
includes/class-sensei-frontend.php
Outdated
wp_register_script( 'sensei-quiz-js', esc_url( Sensei()->plugin_url . 'assets/js/frontend/quiz' . $suffix . '.js' ), array( 'jquery' ), '1', true ); | ||
wp_enqueue_script( 'sensei-quiz-js' ); | ||
wp_localize_script( 'sensei-quiz-js', 'quizL10n', array( | ||
'empty_response_warn' => __( 'Some responses are empty! Are you sure you want to submit?' ) |
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.
Missing a trailing comma.
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.
Fixed
assets/js/frontend/quiz.js
Outdated
button.removeAttr( 'clicked' ); | ||
|
||
// Only continue for the "Complete Quiz" button | ||
if ( button.attr( 'name' ) != 'quiz_complete' ) { |
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.
So if I understand this correctly - this should not show the modal when pressing the Complete Quiz button ?
I'm asking as that still shows the modal for me and I'm actually wondering if we'd want such behaviour at all instead of always showing it when there are some empty fields ?
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.
Actually, this should only show the modal when the user clicks the Complete Quiz button. If the button is not Complete Quiz, then we return here.
This is because the warning only makes sense (in my opinion) when the user is submitting the quiz to be graded. If they are clicking on Reset Quiz or Save Quiz, for example, then I don't think we need to warn them of empty responses.
Does that make sense?
I'm not seeing this box. Can you share a screenshot please? Thx! |
This avoids having an "if" statement without braces, which can cause potential issues down the road. The ternary statement in this case is more succinct, and safer.
Thanks! Was looking for it at the question level.
I agree. This is not very good UX. 😄 Ideally we would use a modal here. There are actually a fair number of places in Sensei that would benefit from having one. Given that would be a fairly large endeavour though, for the purposes of this change, showing an inline message sounds like an acceptable alternative. You could model it after this type of message that Sensei already has: |
Changed to a warning on the page, styled along with the rest of the site, instead of a JS alert box.
Pushed the new warning dialog for empty responses: I think it looks ok. Maybe not fantastic. But it's pretty consistent with the rest of the UI though. Might want to tweak the colorscheme a bit. I'm not sure about the yellow and blue? Would love to get some thoughts here. @donnapep @ice9js I added some complexity in order to get this to work ( |
@alexsanford @pgk In going through existing Sensei issues, there are a couple of related issues that could also affect or be affected by this change, specifically #1509 and #1488. I wonder if perhaps we should slow down a bit, and think about the overall quiz-taking flow at a high-level. Maybe in the end we'd put this change in after all, but at least we'd have done a thorough review first and determined what the optimal quiz workflow should be before pushing changes that later we realize we don't want or need. Thoughts? |
Adding this to future milestone along with the pr |
Hi, is there any chance to see this feature sooner or later? In our process, it is extremely penalizing that our users can submit quiz by leaving some replies empty or by not replying to questions. It is even more problematic because there's no history of submitted quizzes. Meaning, if a user forgot one "answer" to a quiz, we do not validate the lesson, we ask them to then reset their quiz and we lose all the initial replies he already submitted. Of course in this case we request them to only reply to the "forgotten" question. There could be an optional feature at least in the back-end that, when enabled, automatically repopulates the fields of the quiz with all previous given answers upon "reset the quiz" button hit. It will save our users and ourselves tons of time and lots of hassles. Thanks for the great work guys anyway! |
@AiramMontessori There are a number of issues that have been reported with quizzes recently. We've realized that this is one area of Sensei that would benefit greatly from a full review of current functionality. Until that is done, I'm wary of introducing small changes such as this one, which we could easily realize later wasn't properly thought through and perhaps even makes it more difficult to make other improvements. For that reason, this change won't be going into Sensei in its current form. But rest assured that we will be taking a good hard look at the existing quiz functionality to see what improvements can be made there. I've copied your comment over to #1718 as it's related to the discussion on that issue. Thx. |
Fixes #1718
Adds a new option to quizzes. When this option is enabled, users taking the quiz will see a warning if they have left any responses blank. They may still opt to submit the form with the blank responses.
Testing
Notes
This iteration will only warn the user. There is no option to actually prevent the user from submitting if there are empty responses.
We're just using a JS dialog here. I'm not sure that's what we want from a design perspective. Are there any modal dialogs that we use elsewhere on the frontend in Sensei? Alternatively I could just display a message right in the html. But I think the alert works for now.
I had to do a couple of hacky things in JS (no surprise there...) but I tried to make the code as clean as possible. Please feel free to call me out on anything nasty, and I can clean it up.
There are no tests for the JS functionality. @pgk I couldn't find any obvious existing JS tests. I'm assuming we don't have anything set up yet?
I set up gulp to do more JS minification, and updated the minified files across the board
The function
sensei_quiz_action_on_empty_response
is set up so that we could add other actions later (e.g.error
)