0

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

1

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}`);
}
| improve this answer | |
  • 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 – sally yamak Apr 12 '19 at 12:56
  • Okay @JayantDas your answer will be marked as correct answer – sally yamak Apr 12 '19 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? – user682217 Nov 22 '19 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. – Jayant Das Nov 22 '19 at 16:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.