Campos obrigatorios

Pessoal, como consigo colocar campos tipos "zoom" como obrigatório no script abaixo?

<script type="text/javascript" charset="utf-8">
        var textosAlertas = [];
        var alert ='<h4><b>Campo(s) obrigatório(s) não preenchido(s):</b></h4>';    

        textosAlertas['nm_nome']='=> Nome';
        textosAlertas['vl_telefone']='=> Telefone';
        textosAlertas['vl_idade']='=> Idade';
        textosAlertas['cb_sexo']='=> Sexo';
        textosAlertas['vl_cep']='=> CEP';
        textosAlertas['nm_cidade']='=> Cidade';
        textosAlertas['nm_lougradouro']='=> Lougradouro';
        textosAlertas['nm_complemento']='=> Complemento';
        textosAlertas['nm_bairro']='=> Bairro';
        textosAlertas['nm_estado']='=> Estado';        
        textosAlertas['zoom_Func']='=> Lista de Funcionários';
        textosAlertas['cb_formacao']='=> Formação Escolar';
        textosAlertas['zoom_Area']='=> Possível área de atuação';
        textosAlertas['zoom_Profissoes']='=> Possíveis Profissões';    

        var beforeSendValidate = function(numState, nextState) {
        var camposObrigatorios = new Array();
        /* Limpa campos que estavam com erro da validação anterior */
        $(".has-error").removeClass("has-error");

        $(".has-free").each(
            function() {
                var tag = $(this).prop("tagName");
                switch (tag) {
                case "INPUT":
                    var tipo = $(this).prop("type");
                    if (tipo == "radio") {
                        var checado = $("[name='"+ $(this).prop("name") + "']:checked");
                        if(checado.length == 0){
                            if(camposObrigatorios.indexOf($(this).prop("name")) < 0){
                                camposObrigatorios.push($(this).prop("name"));
                                $(this).closest(".radio").addClass("has-error");
                            }
                        }
                    } else if (tipo == "checkbox") {
                        if ($(this).checked == false) {
                            camposObrigatorios.push($(this).prop("name"));
                            $(this).closest(".form-group").addClass("has-error");
                        }
                    } else {
                            switch ($(this).prop("id")){
                                case "zoom_Func":
                                    if($("#cb_ProRet").val() == "S"){
                                        if ($(this).val() == ""){
                                            camposObrigatorios.push($(this).prop("name"));
                                            $(this).closest(".form-group").addClass("has-error");
                                        }
                                    }
                                break

                                default:
                                if ($(this).val() == ""|| $(this).val() == 'mm/dd/yyyy'|| $(this).val() == 'dd/mm/aaaa'){
                                    camposObrigatorios.push($(this).prop("name"));
                                    $(this).closest(".form-group").addClass("has-error");
                                }
                            }

                        }
                    break;
                    case "SELECT":
                        if ($(this).val() == "") {
                            camposObrigatorios.push($(this).prop("name"));
                            $(this).closest(".form-group").addClass("has-error");
                        }
                    break;
                    case "TEXTAREA":
                        switch ($(this).prop("id")){
                        default :
                            if ($(this).val() == "") {
                                camposObrigatorios.push($(this).prop("name"));
                                $(this).closest(".form-group").addClass("has-error");
                            }
                        }
                }
            });            

            var txtErro ='';
            if (camposObrigatorios.length > 0) {
                txtErro = alert;
                for ( var i = 0; i < camposObrigatorios.length; i++) {
                    if (textosAlertas[camposObrigatorios[i]] != '') {
                        txtErro += "\n" + textosAlertas[camposObrigatorios[i]];
                    }
                }

            }
            console.info('TESTE');    

            if(txtErro!=''){throw (txtErro);}

    };                
    </script>
compartilhar
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do fluig Forum!

-1 resposta

Não é a resposta que estava procurando? Procure outras perguntas com as tags formulario ou faça a sua própria pergunta.