Skip to content
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

Courses: Fix Exam error messages #6752

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open

Courses: Fix Exam error messages #6752

wants to merge 6 commits into from

Conversation

jsschf
Copy link
Member

@jsschf jsschf commented Jul 6, 2020

Fixes #3784

@jsschf
Copy link
Member Author

jsschf commented Jul 6, 2020

Looking at this issue again, there are now only two of the four tasks left:

1. The main "Some required fields are missing" message should go away after all errors are fixed.

2. The error message "You must add a choice..." does not show up.  This should only show up for multiple choice question types, never text question types.

I think the first one will be much more difficult than the second, so we might need to split this into two PRs.

@paulbert The "You must add a choice" error message does pop up when a choice is added and then removed.

Annotation 2020-07-06 173246

Also, I was unable to get that error message to pop up on text questions, it only showed up on multiple choice questions.

I think the reason the main "Some required fields are missing error" won't go away dynamically is because it's based of a boolean in ExamsAddComponent that only changes when the form is trying to be submitted. I'm not sure how to fix that issue. I'm not sure if you could have that variable sent to ExamsQuestionComponent, and then emit its value on change back to ExamsAddComponent.

Any guidance would be appreciated.

@jsschf jsschf removed the question label Jul 7, 2020
@jsschf
Copy link
Member Author

jsschf commented Jul 8, 2020

@paulbert My most recent commit is the idea I have to get the "Some required fields are missing" in ExamsAddComponent to automatically go away when the choices in ExamsQuestionComponent are valid.

I'm not sure why it's not working. Any guidance would be appreciated.

@jsschf jsschf added the question label Jul 8, 2020
@jsschf jsschf requested a review from paulbert July 8, 2020 23:40
@jsschf jsschf removed the question label Jul 10, 2020
@jsschf jsschf removed the WIP label Jul 10, 2020
@jsschf
Copy link
Member Author

jsschf commented Jul 10, 2020

Two things:

  • I moved the "You must add a choice" error message below the "Add choices" button, otherwise it was shifting the choices as it showed up or disappeared from the view.
  • I'm struggling to get the "You must select the correct choice" to show up

Copy link
Member

@paulbert paulbert left a comment

Choose a reason for hiding this comment

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

In addition to the note below, it would be better to keep showFormError local to ExamsAddComponent only.

Using statusChanges on the form in ExamsAddComponent would be preferred.

I think the statusChanges is needed for the choices, but you can have a local showChoicesError on the ExamsQuestionComponent instead. The other condition in the *ngIf for the choices error can be removed because it is not working.

@@ -59,6 +60,11 @@ export class ExamsQuestionComponent implements OnInit, OnChanges, AfterViewCheck
this.choiceAdded = false;
this.cdRef.detectChanges();
}
this.choices.statusChanges.subscribe((data) => {
if (data) {
this.choices.valid ? this.showFormError = false : this.showFormError = true;
Copy link
Member

Choose a reason for hiding this comment

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

You shouldn't run statements as clauses with a ternary operator. It makes it more difficult to read.

In this case you can pretty easily invert this so it's an assignment to this.showFormError based on this.choices.valid.

@jsschf
Copy link
Member Author

jsschf commented Jul 13, 2020

@paulbert When you are talking about keeping showFormError local to ExamsAddComponent, and showChoicesError local to ExamsQuestionComponent, are you saying that those two properties shouldn't be bound to each other?

Also, do I need to put statusChanges into ngAfterViewChecked? If so, I'm having trouble preventing the "Some required fields are missing error" from displaying right as the page loads.

Also if you want me to put it into ngAfterViewChecked then there are two many functions in ExamsAddComponent and Code Climate fails. I'm not sure how to refactor to pass that.

@paulbert
Copy link
Member

@jsschf Yes. The 2-way binding is incomplete in this implementation, anyway, but ExamsQuestionComponent should not be passing its show error value back up to ExamsAddComponent and it's not necessary to pass the value down.

statusChanges does not need to go in ngAfterViewChecked in ExamsAddComponent. You can actually put it right after the examForm assignment in createForm().

I'm seeing the error message show up immediately when adding a question. In statusChanges you should reset the showFormError to false if the form is invalid and otherwise don't change it. That way the message will only show up after the user tries to submit the form.

@jsschf jsschf removed the question label Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ExamsQuestion: Clean up validation messages
2 participants