I'm working on lightning Web Component and i have a combobox.
In the Template file i have @track value=''
to save my selected value
when i change the variable name from @track value=''
to
@track selectedValue=''
my combobox it's not working...
can anyone know why i should only use @track value
as variable name to save the selected value in the combobox
Add a comment
|
1 Answer
There is no such restriction to use only the name value
. You will need to make sure if you change the name in the JS, the same is updated in the HTML as well.
As an example the below works perfectly fine:
HTML
<lightning-combobox
name="status"
label="Status"
placeholder="Choose Status"
value={selectedValue} // make sure you update the variable name here as well
onchange={handleChange}
options={statusOptions}>
</lightning-combobox>
JavaScript
@track
statusOptions = [
{value: 'new', label: 'New'},
{value: 'in-progress', label: 'In Progress'},
{value: 'finished', label: 'Finished'}
];
@track
selectedValue = 'new';
handleChange(event) {
this.selectedValue = event.detail.value;
alert(`Option selected with selectedValue: ${this.selectedValue}`);
}
-
thank you for your fast reply everything i did is correct but my fault came from my apex class... i retry this and it's working now Commented Apr 12, 2019 at 12:56
-
Okay @JayantDas your answer will be marked as correct answer Commented Apr 12, 2019 at 13:32
-
I'm having problems with my combobox. I pasted your code and the behaviour is the same.After selection the combo shows the placeholder instead of the selected label. What could be the cause? Commented Nov 22, 2019 at 16:15
-
@user682217 This question was specific on what "name" can a variable have. You may like to open a new question and point out exactly what your issue is. But your attribute/variable name should be same on the component and the JS to ensure things work appropriately. Commented Nov 22, 2019 at 16:47