|
@@ -70,11 +70,53 @@ export default class extends Component {
|
|
|
|
|
|
checkAnswer() {
|
|
|
const { question } = this.props;
|
|
|
+ const { content } = question;
|
|
|
const { answer } = this.state;
|
|
|
- let result = null;
|
|
|
- if (!answer) return this.showToast('Answer Required', 'You can not continue with this question unanswered. ', 430);
|
|
|
- if (question.questionType === 'awa' && !answer.awa) result = 'Please answer the question first.';
|
|
|
- if (result) return this.showToast(null, result);
|
|
|
+ let title = null;
|
|
|
+ let desc = null;
|
|
|
+ let width = null;
|
|
|
+ if (question.questionType === 'awa' && !answer.awa) {
|
|
|
+ desc = 'Please answer the question first.';
|
|
|
+ } else {
|
|
|
+ let flag = false;
|
|
|
+ if (!answer || !answer.questions) {
|
|
|
+ flag = true;
|
|
|
+ } else if (content.type === 'double') {
|
|
|
+ answer.questions.forEach((row, index) => {
|
|
|
+ if (flag) return;
|
|
|
+ if (!row.double) {
|
|
|
+ flag = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const { direction } = content.questions[index];
|
|
|
+ switch (direction) {
|
|
|
+ case 'landscape':
|
|
|
+ flag = row.double.filter(r => (r || []).filter(rr => rr).length > 0).length < row.double.length;
|
|
|
+ break;
|
|
|
+ case 'portrait':
|
|
|
+ flag = [0, 1].map(r => row.double.filter(rr => rr && rr[r]).length > 0) < 2;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else if (content.type === 'single') {
|
|
|
+ answer.questions.forEach((row) => {
|
|
|
+ if (flag) return;
|
|
|
+ if (!row.single) {
|
|
|
+ flag = true;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ flag = row.single.filter(r => r).length === 0;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (flag) {
|
|
|
+ title = 'Answer Required';
|
|
|
+ desc = 'You can not continue with this question unanswered. ';
|
|
|
+ width = 430;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (title || desc) return this.showToast(title, desc, width);
|
|
|
return true;
|
|
|
}
|
|
|
|