Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

Rev 364 | Rev 366 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 364 Rev 365
Línea 2... Línea 2...
2
import Question from "../question/Question";
2
import Question from "../question/Question";
Línea 3... Línea 3...
3
 
3
 
Línea 4... Línea 4...
4
const Section = (props) => {
4
const Section = (props) => {
5
 
5
 
Línea 6... Línea 6...
6
    // get props
6
    // get props
7
    const { section, backendVars, handleAnswer, page, setPage } = props;
7
    const { section, backendVars, handleAnswer, page, setPage, total } = props;
Línea 8... Línea 8...
8
 
8
 
9
    //init states 
9
    //init states 
10
    const [error, setError] = useState('');
10
    const [errors, setErrors] = useState([]);
11
 
11
 
12
    /**
12
    /**
13
     * Check if there are questions to answer
13
     * Check if there are questions to answer
14
     * @returns 
14
     * @returns 
-
 
15
     */
15
     */
16
    const validateSection = () => {
16
    const validateSection = () => {
17
        setErrors('');
17
        setError('');
18
        let formValid = true;
-
 
19
        messages = [];
18
        let formValid = true;
20
        section.questions.map((question) => {
19
        section.questions.map((question) => {
21
            //Validate if the answer is empty
20
            //Validate if the answer is empty
22
            if (!question.answer) {
-
 
23
                messages.push(backendVars.LBL_EMPTY_ANSWER.replace('%n', question.position + 1));
21
            if (!question.answer) {
24
                formValid = false;
22
                formValid = false;
25
            }
Línea 23... Línea 26...
23
            }
26
        });
24
        })
27
        setErrors(messages);
Línea 65... Línea 68...
65
                                    handleAnswer={handleAnswer}
68
                                    handleAnswer={handleAnswer}
66
                                />;
69
                                />;
67
                            })}
70
                            })}
68
                        </div>
71
                        </div>
69
                        <div className="row">
72
                        <div className="row">
-
 
73
                            {errors.length > 0 &&
70
                            <div className="col-md-12 text-right np-padding">
74
                                <div className="col-md-12 np-padding">
-
 
75
                                    {errors.forEach((error, index) => {
71
                                <div class="alert alert-danger" role="alert">
76
                                        <div class="alert alert-danger" role="alert" key={index}>
72
                                    This is a danger alert—check it out!
77
                                            {error}
-
 
78
                                        </div>
-
 
79
                                    })}
73
                                </div>
80
                                </div>
74
                            </div>
81
                            }
75
                            <div className="col-md-12 text-right np-padding">
82
                            <div className="col-md-12 text-right np-padding">
76
                                <ul class="wizard">
83
                                <ul class="wizard">
-
 
84
                                    {section.position != 0 &&
77
                                    <li class="previous">
85
                                        <li class="previous">
78
                                        <button
86
                                            <button
79
                                            type="button"
87
                                                type="button"
80
                                            className="btn btn-secondary"
88
                                                className="btn btn-secondary"
81
                                            onClick={() => handlePrevious()}
89
                                                onClick={() => handlePrevious()}
82
                                            disabled={section.position == 0}
-
 
83
                                        >
90
                                            >
84
                                            {backendVars.LBL_SELF_EVALUATION_TEST_FORM_PREVIOUS}
91
                                                {backendVars.LBL_SELF_EVALUATION_TEST_FORM_PREVIOUS}
85
                                        </button>
92
                                            </button>
86
                                    </li>
93
                                        </li>
-
 
94
                                    }
-
 
95
                                    {section.position != total - 1 &&
87
                                    <li class="next">
96
                                        <li class="next">
88
                                        <button
97
                                            <button
89
                                            type="button"
98
                                                type="button"
90
                                            onClick={() => handleNext()}
99
                                                onClick={() => handleNext()}
91
                                            className="btn btn-secondary">
100
                                                className="btn btn-secondary">
92
                                            {backendVars.LBL_SELF_EVALUATION_TEST_FORM_NEXT}
101
                                                {backendVars.LBL_SELF_EVALUATION_TEST_FORM_NEXT}
93
                                        </button>
102
                                            </button>
94
                                    </li>
103
                                        </li>
-
 
104
                                    }
95
                                </ul>
105
                                </ul>
96
                            </div>
106
                            </div>
97
                        </div>
107
                        </div>
98
                    </div>
108
                    </div>
99
                </div>
109
                </div>