Topic: Select option is not update correctly if a option is already select
arthur s free asked 4 years ago
I look for update select option thank's to a Ajax request. It's work's unless a option has been selected by user.
If a option has been selected html continue to be update by request but render stop to be update, i have to refresh page.
function sendAjax($url, $datas = null, $methode="GET") {
if ($datas != null) {
// console.log($datas);
$.ajax({
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
url: $url,
type: $methode,
data: $datas,
contentType: false,
cache: false,
processData: false
}).done(function (response) {
console.log(response);
$html = '<option value="" disabled selected>Choisissez la taille de votre article</option>';
for (let i = 0; i < response.length; i++) {
$html = $html + '<option value="'+response[i].id+'">'+ response[i].size +' '+ response[i].unit +'</option>';
}
console.log($html);
$size = $("#size_id")
$size.removeAttr('disabled')
$size.children().each(function () {
$(this).removeAttr('selected')
$(this).remove()
})
$size.append($html);
});
}
else {
console.error("No data to send !");
return false;
}
}
Tomek Makowski staff answered 4 years ago
Hi
If it is material select try to reinitialize its. To do this firstly delete material select
$(".material-select").materialSelect({destroy: true})
then initialize it again
$(".material-select").materialSelect()
If it doesn't work please show me your full code in the snippet editor: https://mdbootstrap.com/snippets/
Regards
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB jQuery
- MDB Version: 4.17.0
- Device: Desktop
- Browser: Firefox
- OS: W10
- Provided sample code: No
- Provided link: No