Old value after failed validation

Im trying to keep the old value of a select2, the data is getting from a ajax response,
$('#patient').select2({
minimumInputLength: 3,
ajax: {
url: '{{ route("api.patients.search") }}',
dataType: 'json',
method:'GET',
processResults: function (data) {
// console.log(data); // Log the data to the console
return {
results: data.results.map(function(patient) {
return {
id: patient.id,
text: patient.text + " - " + patient.name,
};
})
};
}
},
});
$('#patient').select2({
minimumInputLength: 3,
ajax: {
url: '{{ route("api.patients.search") }}',
dataType: 'json',
method:'GET',
processResults: function (data) {
// console.log(data); // Log the data to the console
return {
results: data.results.map(function(patient) {
return {
id: patient.id,
text: patient.text + " - " + patient.name,
};
})
};
}
},
});
and the blade code <x-form.searchable-select-input for_label="patient_id" label="Patient" id="patient" name="patient_id" error_label="patient_id"> <option value="" selected>Select a Patient</option> </x-form.searchable-select-input> i tried many ways. but didnt succeeded. Old value did not select when a validation error occurs.
No description
2 Replies
tuto1902
tuto1902•8mo ago
may I ask why are you using a select2 component? The searchable() select from filament can handle this kind of task pretty well without using third party components
shaan
shaan•8mo ago
oh, this is a old project. will start a filament one soon 😄