bootstrapValidator.js with jsf does not work

2

My validation script using bootstrapValidator.js

<h:outputScript library="primefaces" name="jquery/jquery.js" target="head" />
<h:outputScript library="primefaces" name="jquery/jquery-plugins.js" target="head" />

    <script type="text/javascript">
        $ = jQuery;
        $(document).ready(function() {
            $('#formAgendaMedica').bootstrapValidator({
                live : 'disabled',
                fields : {
                    'formAgendaMedica:paciente_input' : {
                        validators : {
                            notEmpty : {
                                message : 'Informe o paciente'
                            }
                        }
                    },
                    'formAgendaMedica:progama_input' : {
                        validators : {
                            notEmpty : {
                                message : 'Informe o programa'
                            }
                        }
                    },
                    'formAgendaMedica:grupo_input' : {
                        validators : {
                            notEmpty : {
                                message : 'Informe o grupo'
                            }
                        }
                    },
                    'formAgendaMedica:atendimento_input' : {
                        validators : {
                            notEmpty : {
                                message : 'Informe o atendimento'
                            }
                        }
                    }
                }
            });
        });
    </script>

The scenario is as follows, I open my screen that has the form that I'm validating with script above, however you can see that I'm validating 4 fields that can not be null.

First test:

As soon as I open the form I submit submit to see if it is working, however in my DOM it is only rendered still patient_input and progama_input, so far worked perfectly if it has null it correctly execute the script.

ButtheothertwofieldsarerenderedwhenIfillintheprogama_inputfield,donethiswhenI'mgoingtotestifgroupandattendanceisnullblockthesubmitjsfdoesaredirecttothesamepageandstillcomesbackwiththefollowingerrorintheconsole.

Noticeintheimagebelowthatgroupisnowaccessible.

WhenIsubmitagaintotestthenullofthegroupinput,jsfdoesaredirectandreturnsthat.

    
asked by anonymous 08.11.2016 / 15:10

2 answers

1

Another way to avoid conflicts when using jQuery is to isolate its use within an IIF function. Example:

+function($){

//Insira todo seu código aqui    

}(jQuery);
    
08.11.2016 / 16:22
1

You can not use this way

  

$ = jQuery;

Replace all $ with JQuery , this causes conflicts with the firstfaces lib, I know that JQuery and Other JS say you can do what you did.

But it does not work!

I always use JQuery instead of $, when I put libs .js in my projects I always have to hit it that way to work.

Your script loader also seems to be wrong: we use it here

<!-- para usar JQuery nos scripts -->
<h:outputScript library="primefaces" name="jquery/jquery.js" />
<h:outputScript library="primefaces" name="primefaces.js" />

Another detail within the head tag of the view

    
08.11.2016 / 15:22