0
get floraValues() {
    let values = [];
            
    if (this.managementaction && this.managementaction.bb01_Recommended_Flora__c) {
      for (let str of this.managementaction.bb01_Recommended_Flora__c.split(";")) {
                    
       // values.push(str);
                    values.push({
                label:this.managementaction.Name ,
                value: str
            })
      }
    }
    alert(JSON.stringify(values));
     
    return values;
}

I can see in console logs , values are coming correct but not shown in the component. Below is the HTML .

<lightning-dual-listbox
     name="floras"
     label="Flora"
     source-label="Available"
     selected-label="Selected"
     field-level-help="Select Flora"
     options={floraOptions}
     value={floraValues}
     class="flora"
></lightning-dual-listbox>

1 Answer 1

2

The issue might be here :

values.push({
     label:this.managementaction.Name ,
     value: str
})

As per doc, you need to only send values and nothing else.

get floraValues() {
    let values = [];

    if (this.managementaction && this.managementaction.bb01_Recommended_Flora__c) {
        for (let str of this.managementaction.bb01_Recommended_Flora__c.split(";")) {
            values.push(str)
        }
    }
    return values;
}


get floraOptions() {
    let values = [];

    if (this.managementaction && this.managementaction.bb01_Recommended_Flora__c) {
        for (let str of this.managementaction.bb01_Recommended_Flora__c.split(";")) {

            // values.push(str);
            values.push({
                label:this.managementaction.Name ,
                value: str
            })
        }
        values.push({
            label:'NewLabel' ,
            value: 'NewValue'
        })
    }
    return values;
}

I just created a dummy data like this

managementaction = {
    bb01_Recommended_Flora__c : "Test1;Test2",
    Name : "TestName"
}

And result is :

enter image description here

2
  • I tried with this - if (this.managementaction && this.managementaction.bb01_Recommended_Flora__c) { for (let str of this.managementaction.bb01_Recommended_Flora__c.split(";")) { values.push(str) } } but this only bring the first value and not the values after ; Commented Jan 8 at 4:56
  • Just found the root cause of the error - In the field "bb01_Recommended_Flora__c" values are stored in ; separated format. There was a space after ; in the values because of which only first value was appearing in the selected window. But yes you are correct, if (this.managementaction && this.managementaction.bb01_Recommended_Flora__c) { for (let str of this.managementaction.bb01_Recommended_Flora__c.split(";")) { values.push(str) } } works perfectly fine. Thanks @Nagendra Commented Jan 8 at 5:05

You must log in to answer this question.

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