I'm working on a process that update a picture with bootstrap file input, everything works fine but i can not achieve change the title of the input file after the process was finished.
For those who don't know bootstrap file input, when the file was choseen the name of the file takes the title of the input file.
I try:
$("#userPicture").prop('title', 'Select picture...');
and:
$("#userPicture").attr('title', 'Select picture...');
But neither of both works.
This is the container:
<form method="post" id="fileinfo" name="fileinfo" class="form-horizontal" onsubmit="return submitForm();" role="form">
<input type="file" id="userPicture" name="userPicture" title="Select picture..." class="btn btn-primary btn-xs" data-filename-placement="inside"><br><br>
<div style="display:inline-block;">
<button type="button" class="btn btn-success btn-block btn-xs" style="width:80px;" id="pictureSave">Save</button>
</div>
<div style="display:inline-block;">
<div id='loadingmessage' style="font-family: 'Open Sans', sans-serif;font-size:12px;display:none" align="center"> <img src="img/loader.gif"></div>
</div>
</form>
This is the function:
$(document).on('click','#pictureSave',function() {
var studentPicture = $("#userPicture").val();
var studentId = $("#studentId").val();
if (studentPicture === "") {
$("#pictureResponse").html('<p class="text-danger">You must to select a picture.</p>');
} else {
$('#loadingmessage').show();
var fd = new FormData(document.getElementById("fileinfo"));
fd.append("action", "changeStudentPicture");
fd.append("studentId", studentId);
$.ajax({
url: "content/studentsAction.php",
type: "POST",
data: fd,
enctype: 'multipart/form-data',
processData: false,
contentType: false
}).done(function(data) {
if (data != "Successful") {
$('#loadingmessage').hide();
$("#pictureResponse").html('<p class="text-danger">'+data+'</p>');
} else {
$('#loadingmessage').hide();
$("#userPicture").prop('title', 'Select picture...'); //Here is the issue
$("#pictureResponse").html('<p class="text-success">The picture was updated successfully.</p>');
}
});
}
});
For your information, i found the solution analyzing the bootstrap.file-input.js
$(".file-input-wrapper input[type=file]").siblings('span').html('Select picture');