• Daniel Martinez 73
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
Hi,

I'm trying to remove options in lightning:inputField but I didn't know how to do it.

User-added image

This status returns Active, Cancelled, Draft, Completed. I would like to remove Active and Completed. I tried to do it with 2 ways.

loadStatusOptions : function (component, event, helper) {
var inputStatus = document.querySelectorAll('[id$="myPicklist"]')[0];
console.log('inputStatus: ' + JSON.stringify(inputStatus));
var selectobject = component.find('status_program');
console.log('selectobjectselectobject: ' + JSON.stringify(selectobject));
if(inputStatus){
for (var i = 0; i< inputStatus.length; i++){
if (inputStatus.options[i].value == 'Active'){
inputStatus.remove(i);
}
}
}
}
How do I populate a lightning-combobox with options from an Apex controller?

I have the following, but the combox doesn't show any options. I can see the alert popup with the option Name it's just not diplaying in the combobox.

HTML
<template>
    <lightning-combobox
        name="recentReports"
        label="Report"
        placeholder="Select Report"
        value={value}
        options={reportOptions}
        onchange={handleRecentReportsChange} >
    </lightning-combobox>
</template>

JS
import { LightningElement, track, wire } from 'lwc';
import getRecentReports from '@salesforce/apex/ReportController.getRecentReports';

export default class ReportLink extends LightningElement {
    @track reportOptions = [];
    @track value = '';
    
    connectedCallback() {
        getRecentReports()
            .then(result => {
                for (var i = 0; i < result.length; i++) {
                    this.reportOptions.push({label: result[i].Name, value: result[i].Id});
                    alert(result[i].Name);
                }
            })
            .catch(error => {
                alert(JSON.stringify(error));
            });
    }

    handleRecentReportsChange(){

    }

}
Apex
public with sharing class ReportController {
    public ReportController() {

    }

    @AuraEnabled(Cacheable=true)
    public static List<RecentlyViewed> getRecentReports(){
        return [SELECT Id, Name FROM RecentlyViewed WHERE Type = 'Report'];
    }

}


 
  • August 03, 2020
  • Like
  • 0