validate a variable in jquery validate

-1

I am using jquery.validate and I have the following problem, I have an image field, that when the image does not exist I fill it with a img by default ... but I need that field to be required and it is not an option have the default image saved in bd . I need something like this:

 $('#idForm).validate({
     rules:{
         name:{
             required:true
         },
         photo:{
             required:imgNew?true:false
         }
     }
 })

So what I want to validate is if the variable has value and not if the field has a value. the field img has the following:

<img ng-src="{{imgSrc ? imgSrc : '/images/no-image.jpg'}}" data-  toggle="modal" data-target="#avatar-modal">

In this modal there is a file type input that gives value to the variable imgSrc . What I need is for you to put the poster as jquery.validate does when variable is null or empty. Greetings

    
asked by Gabriel 06.09.2016 в 17:49
source

1 answer

1

The validate only serves to send messages that this field is required in case it does not contain information, the question here is how is your field image? This is loaded by default, this changes by clicking somewhere or as? In any case what you must do is use the option ".val ()" to get the value of that field, this is an example:

var img = $('#IdImagenInput').val();
if (img != "") { //img == "undefined" img != "undefined"... etc 
   var tieneFoto = true/false.. etc
   tus metodos aqui....
}
    
answered by 06.09.2016 в 18:09