I created valid-file
attribute using angular directive because file-input (with bootstrap filestyle plugin) don't see required
attribute :
.directive('validFile',function(){
return {
require:'ngModel',
link:function(scope,el,attrs,ngModel){
//change event is fired when file is selected
el.bind('change',function(){
scope.$apply(function(){
ngModel.$setViewValue(el.val());
ngModel.$render();
})
})
}
}
})
I need to dynamically add or remove valid-file
attribute. If I use $("input").attr("valid-file");
nothing will change. If I use $("input").attr("valid-file",true);
it will add attribute valid-file="true"
but validation will break. Can you advice me something? Here's plunker http://plnkr.co/edit/Gcbb7r05VBTjbh9x5Ma8?p=preview
.attr()
need 2 parameters if you want to set any attribute in any element.
ex. $("input").attr("valid-file","");
// empty will also ok..or any value instead of empty
because only $("input").attr("valid-file")
is used to get value of attribute "valid-file"
So you need 2 parameter in .attr()
to set any attribute
Try this: http://plnkr.co/edit/lSl3GdZrRAyFps5QOSlw?p=preview
$("select").change(function(){
if ($("select option:selected").val() == "0") {
$("input").attr("valid-file",""); // try this
} else {
$("input").removeAttr("valid-file");
}
});
HTML:
<select name="" id="">
<option value="">Select</option>
<option value="0">Add attr
<option value="1">Delete attr
</select>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments