0

Here I have a form and I need to validate form. I have select2 input fields and this fields I cant validate with parsley plugin so I write my code...

Problem is how to at same time check if validate = true and select2 inputs ===null...

I write:

$(function() { 
    $('#myForm').submit(function(e) { 
        e.preventDefault();

        if ( $(this).parsley('validate') ) {                
            if ($("#parcele").select2("data")== null || $("#vrsta_rada").select2("data")== null) {
                $('#parerror').show();
                console.log('nema dalje');
            } else {                
                var zemljiste = $("#parcele").select2("data").naziv;
                var id_parcele = $("#parcele").select2("data").id;
                var vrsta_rada = $("#vrsta_rada").select2("data").text;    

                $.ajax({
                    url: "insertAkt.php",
                    type: "POST",
                    async: true, 
                    data: { naziv:$("#naziv").val(),parcele:zemljiste,vrsta_rada:vrsta_rada,opis:$("#opis").val(),pocetak:$("#pocetak").val(),zavrsetak:$("#zavrsetak").val(),status:$("#status").val(),id_parcele:id_parcele,}, //your form data to post goes here as a json object
                    dataType: "html",

                    success: function(data) {
                        $('#myModal').modal('hide');
                        drawVisualization();
                        console.log('USPEH'); 
                        console.log(data);  
                    }, 
                    error: function (data) {
                        console.log(data);
                        console.log('GRESKA NEKA');
                    }
                });
            }
        }
    });
}); 

but as you can see my code first check form validation after that select2 inputs so how I can at same time check form and select2 inputs fields?

1 Answer 1

2

By using && operator you can check both condition at the same time

if ( ($(this).parsley('validate')) && ($("#parcele").select2("data") === null)) { }

Sign up to request clarification or add additional context in comments.

1 Comment

hm, I cant show error on select2 fields at same time ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.