0

I have a array like below in lwc js.
I need display the value in combo box. Currently I am passing the variable which assign the prevoius array like below.

  1. But it's not displaying value???? in combo box.
  2. I need to do one more chanage in combobox that is if the value is not primary combo box disabled should be enable.Anybody have the answer for those tow Qectins.
@track address = [];
this.address = [
    {
        "label": "614 Washington St-HOBOKEN-UNITED STATES",
        "value": "Primary"
    }
]
<lightning-combobox name="Test"
    label="Test" value={this.address} 
    options={this.address} 
    onchange={handleKeyChange}
    disabled = true
></lightning-combobox>
1
  • 1
    You might need to use a getter for address, check example in the documentation. You may want to clarify the second question, its confusing.
    – Raul
    Mar 21, 2022 at 22:19

2 Answers 2

0

First question, the options property and the value property should not be assigned to the same variable.

addressValue = []
get addressOptions() {
  return [
    {
      label: '614 Washington St-HOBOKEN-UNITED STATES',
      value: 'Primary',
    },
  ]
}
<lightning-combobox
  name="Test"
  label="Test"
  value={this.addressValue}
  options={this.addressOptions}
  onchange={handleKeyChange}
  disabled
></lightning-combobox>

disabled doesn't need ="true". The tag being there already makes it true.


Still a tad unsure what you're asking in that second question, but I think you're after a conditionally disabled field?

Using a getter here should do the trick.

get isDisabled() {
  return this.addressValue === 'Primary'
}

In the markup, you can use the getter on the disabled attribute.

<lightning-combobox
  name="Test Field to be disabled"
  label="Test Field to be disabled"
  onchange={handleKeyChange}
  disabled={isDisabled}
></lightning-combobox>
1
  • 1
    Thank You All, I'll give a try using your suggessions
    – Basu
    Mar 22, 2022 at 4:32
0

when passing variables to components, you don't need to use 'this.' In this case it would be:

<lightning-combobox name="Test"
    label="Test" value={address} 
    options={address} 
    onchange={handleKeyChange}
    disabled = true>
</lightning-combobox>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .