Topic: Select setValue does nothing
alex_wearelanded priority asked 6 months ago
Expected behavior
const singleSelectInstance = mdb.Select.getInstance(document.querySelector('#jobContactEmail'));
const c_id = $("#jobContactEmail").find("option").filter(function() {
if($(this).text() === r.r.contact_email){
return $(this);
}
});
console.log($(c_id).val());
const v = $(c_id).val();
singleSelectInstance.setValue(String(v));
i expect it to change the value of the select to the desired selection.
Actual behavior
it does nothing, the select is imported correctly, the select is on the dom is isnt generated by any js or jq the instance is found so im puzzled to why it is not changing the value on screen, for data protection i. cannot show the screen, all i can say is the value display nor data changes.
after i run singleSelectInstance.setValue('1701'); on the inspect tool nothing happens, no error no visual change to the select, nothing.
Resources (screenshots, code snippets etc.)
Kamila Pieńkowska staff answered 6 months ago
I've changed your snippet so setValue woud work properly: https://mdbootstrap.com/snippets/standard/kpienkowska/6106945
Using selected
attribute to set initial value would break select visually. If you won't to preset value you need to use setValue option.
alex_wearelanded priority answered 6 months ago
edit for my reply,
it seems to be an issue if you want to setValue to the first option in a select, it sets the value bit it keeps the previous select selected instead of removing it, it also not changing the label to the selected setValue put only if i set the value to the first option in the select
alex_wearelanded priority answered 6 months ago
https://mdbootstrap.com/snippets/standard/alex_wearelanded/6105163
there the snippet but it not working lol just white, i got it to change value on my playground which uses same setup as the area im having issue,
but another problem now, when i click my button it changes to the selected value, but it has not remove the old selected and this isnt a mutiselect, so when i click the old selected it messes up.
this isnt very ideal in bootstrap 4 this was very simple process, bs5 has really complicated a simple task, cant say i am a big fan of bs5
Kamila Pieńkowska staff answered 6 months ago
Please provide a snippet that recreate behavior you describe. I need to be able to replicate your problem to troubleshoot.
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Priority
- Premium support: Yes
- Technology: MDB Standard
- MDB Version: MDB5 7.2.0
- Device: mac
- Browser: chrome
- OS: big sur
- Provided sample code: No
- Provided link: No