0

I have a combobox that looks the following In my JS:

timeValue = 7;
options =[
        { label: 'Last 7 days', value: 7},
        { label: 'Last 30 days', value: 30 },
        { label: 'Last Quarter', value: 120 }
    ]

handleChangeTime(event){
        console.log(event.target.value)
        this.timeValue = event.target.value;
  
    }

in my HTML:

<lightning-combobox
              name="Time Frame"
              label="Time Frame"
              value={timeValue}
              placeholder="Select Time Frame"
              options={options}
              onchange={handleChangeTime} 
              dropdown-alignment =left>
</lightning-combobox>

When I load my LWC, then the Label is well displayed and show "Last 7 Days" my issue is when I change it then the Label become "Select Time Frame"

My console.log show me the right value, 7 or 30 or 120 ..

What am I doing wrong ?

1
  • in options array provide value in single quotes instead of without quotes.this will solve he issue. options =[ { label: 'Last 7 days', value: '7'}, { label: 'Last 30 days', value: '30' }, { label: 'Last Quarter', value: '120' } ] Aug 15, 2022 at 15:05

1 Answer 1

1

As per documentation here, the onchange event has a string return type

enter image description here

And the options value you have used is not in single quotes(represented as a string).

Change the get options() as shown below, code should work fine.

get options() {
       return [ { label: 'Last 7 days', value: '7'},
        { label: 'Last 30 days', value: '30' },
        { label: 'Last Quarter', value: '120' }
      ];
  }
1
  • haa ok .. I needed it as a Number to use it in my apex .. Lesson learned, it works thank you ;)
    – Ben2pop
    Aug 15, 2022 at 15:21

You must log in to answer this question.

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