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

Save base response when radio button with other is used #613

Open
wants to merge 2 commits into
base: MOODLE_404_STABLE
Choose a base branch
from

Conversation

Jenczu11
Copy link

This PR fixes should fix 2 things.

  1. 05b4ad9

Without this you when you are submitting other response containing only spaces no error occurs.
There should be some kind of validation / error when other response contains only spaces.

  1. 36d1644.

When submitting question with other response there was a continue (which applies to foreach / loop) if $answer->value was empty or contained only spaces.
It was skipping saving of original base choice.
So on report page there was no info what user selected / answered.

This commit inverts the logic so base save is always happening.

$onlyspaces = preg_match("/^[\s]*$/", $answer->value);
if ($onlyspaces) {
$answered = false;
}
} else {
Copy link
Contributor

Choose a reason for hiding this comment

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

The above code could be simplified to:
$answered = !empty($answer->value) || !preg_match("/^[\s]*$/", $answer->value);

Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a case for answering "other" with no content?

$record->question_id = $this->question->id;
$record->choice_id = $answer->choiceid;
$record->response = clean_text($answer->value);
$DB->insert_record('questionnaire_response_other', $record);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not 100% sure this is what is desired. If the user didn't select a response, why would a response be saved? Please provide a test case

Copy link
Contributor

@mchurchward mchurchward left a comment

Choose a reason for hiding this comment

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

Left comments inline.

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.

2 participants