I am creating a dynamic form for a hospital. Here i have a problem with data-autocomplete. The problem is after updating json array to data-autocomplete=' ' it is not updating the value of data-autocomplete=' '. AS I am using html(bootstrap) and php templete for my frontend forms so,all links are properly arrenged and one input element similar to this is working fine but i have updated the values using php for that input.
<input type='text' class="form-control ui-autocomplete-input" data-autocomplete='' autocomplete="off" id="patient_type_desc" name="patient_type_desc" class="form-control" />
$.post(url, {"referral":referral}, function(data){
//console.log(data);
$('#patient_type_desc').attr('data-autocomplete', data);
});
This code is updating the value, but in form autocomplete is not populating with suggestions.
The data variable is like below
["name1","name2"]
I tried with this jQuery code also but no use - This code not at all working
$( "#patient_type_desc" ).autocomplete({
source: data
});
My Jquery is like this now
$.post(url, {"referral":referral}, function(data){
//console.log(data);
$( "#patient_type_desc" ).autocomplete({
source: data
});
//$('#patient_type_desc').attr('data-autocomplete', data);
}, "json");
Finally working by adding "json". Thank you for all bro's.
Please check below code, find the fiddle also here Fiddle . Hope this may help you.
<div class="form-group ui-widget">
<label for="plugins">Patient Type desc</label>
<input type='text' class="form-control ui-autocomplete-input" data-autocomplete='' autocomplete="off" id="patient_type_desc" name="patient_type_desc" class="form-control" />
</div>
<script>
$(function()
var patient_type_desc = [
"name1",
"name2",
"name3",
"name4"
];
$("#patient_type_desc").autocomplete({source: patient_type_desc});
$("ul.ui-autocomplete").css("left","450px");
});
</script>
<style>
ul.ui-autocomplete { padding-left: 0; list-style-type: none; border: black 1px solid; display: inline-block;}
ul.ui-autocomplete li:hover { background-color: gray; }
ui-helper-hidden-accessible {display: none;}
</style>