Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

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

Rev 355 Rev 356
Línea 12... Línea 12...
12
    /**
12
    /**
13
     * Send form data
13
     * Send form data
14
     */
14
     */
15
    const handleSubmit = async () => {
15
    const handleSubmit = async () => {
16
        if (validateForm()) {
16
        if (validateForm()) {
-
 
17
            //init form data
17
            const formData = new FormData();
18
            const formData = new FormData();
18
            formData.append("content", JSON.stringify(test));
19
            formData.append("content", JSON.stringify(test));
19
            await axios.post(action,  formData ).then((response) => {
20
            await axios.post(action,  formData ).then((response) => {
20
                if (response.data.success) {
21
                if (response.data.success) {
21
                    console.info('Formulario almacenado');
22
                    console.info('Formulario almacenado');
Línea 33... Línea 34...
33
    const handleAnswer = (slug_section, slug_question, answer) => {
34
    const handleAnswer = (slug_section, slug_question, answer) => {
34
        test.content.filter((section) => {
35
        test.content.filter((section) => {
35
            if (section.slug_section == slug_section) {
36
            if (section.slug_section == slug_section) {
36
                section.questions.map((question) => {
37
                section.questions.map((question) => {
37
                    if (question.slug_question == slug_question) {
38
                    if (question.slug_question == slug_question) {
-
 
39
                        //valid if the question has more than one answer
38
                        question.type == 'multiple' ?
40
                        question.type == 'multiple' ?
39
                            !question.answer ?
41
                            !question.answer ?
40
                                question.answer = [answer] :
42
                                question.answer = [answer] :
41
                                question.answer.push(answer)
43
                                question.answer.push(answer)
42
                            : question.answer = answer;
44
                            : question.answer = answer;
Línea 53... Línea 55...
53
     */
55
     */
54
    const validateForm = () => {
56
    const validateForm = () => {
55
        let formValid = true;
57
        let formValid = true;
56
        test.content.map((section) => {
58
        test.content.map((section) => {
57
            section.questions.map((question) => {
59
            section.questions.map((question) => {
-
 
60
                //Validate if the answer is empty
58
                if (!question.answer) {
61
                if (!question.answer) {
59
                    console.error(`Debe ingresar una respuesta en la pregunta ${question.position + 1} de la sección ${section.name}`);
62
                    console.error(`Debe ingresar una respuesta en la pregunta ${question.position + 1} de la sección ${section.name}`);
60
                    formValid = false;
63
                    formValid = false;
61
                }
64
                }
62
            })
65
            })