I have a bootstrap form with a file input box that is checked on the client-site for valid extensions before submitting.
<div class = "container", id="container">
<form id= "fileinput-form" action="/file" method="POST" >
<div class="form-group col-md-4" >
<input class="form-control" type="file" accept=".csv,.txt" name="inputfile" aria-label="file example">
</div>
<div style="margin-top:10px">
<input class="btn btn-primary" id="submit-file" type="submit" value="Predict">
</div>
</form>
</div>
However, the validation is just triggered after the input box was un-focused (or rather by clicking somewhere). Though, I want to have the validation right after the windows dialog box got closed (file got selected) and without the need to un-focus the input box.
$("#fileinput-form").validate({
rules:{
inputfile: {
required: true,
extension: true
}
},
messages:{
inputfile:{
required: "Please input a file."
}
},
});});
I already tried to add an onchange
function, without any success... Is there any solution?
$("#fileinput-form").on("change",function(e) {
console.log('file changed');
$("#fileinput-form").trigger('blur');
/*$("hidden-input").focus();*/
});
question from:
https://stackoverflow.com/questions/65660852/un-focus-file-input-box-after-file-got-selected-to-validate-input 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…