0

I am trying to set blank values for a few fields that are prepopulated. I'm trying to blank the values in the doinit method of the javascript controller. Below is the code:

Component:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:if isTrue="{!v.recType}">

       <lightning:recordEditForm  objectApiName="RFQ__c" onload="{!c.handleOnload}" recordId="{!v.recordId}"> 

            <div class="slds-form-element__row">
                <div >
                    <lightning:inputField aura:id="Desc" fieldName="Description__c" value ="{!v.RFQObj.Description__c}" required="true"  />
                </div>
                <div class="slds-form-element__row">
                    <div >
                        <lightning:inputField aura:id= "contact" fieldName="Contact__c" value ="{!v.RFQObj.Contact__c}"/>
                    </div>
                </div>

                <div>
                    <lightning:select aura:id="typeA" value ="{!v.RFQObj.Type__c}" name="select1" label="Type" required="true" >
                        <option value="">None</option>
                        <aura:iteration items="{!v.typeP}" var="item">
                            <option value="{!item}" >{!item}</option>
                        </aura:iteration>
                    </lightning:select>
                    <span style="color: #C23930;font-size: .75rem;">{!v.ErrorMessage}</span>
                </div>

                <div>
                    <lightning:inputField aura:id="ReceivedDate" fieldName="RFQ_Received__c" value ="{!v.RFQObj.RFQ_Received__c}" required="true" messageWhenValueMissing="Please select a valid date"/>
                    <span style="color: #C23930;font-size: .75rem;">{!v.ErrorMessage1}</span>
                </div>

                <div>
                    <lightning:inputField aura:id="RequestedDate" fieldName="Requested_By__c" value ="{!v.RFQObj.Requested_By__c}" required="true" messageWhenValueMissing="Please select a valid date"/>
                    <span style="color: #C23930;font-size: .75rem;">{!v.ErrorMessage2}</span>
                </div>
                <div>
                    <lightning:inputField aura:id="AssignedTo" fieldName="Assigned_To__c" value ="{!v.RFQObj.Assigned_To__c}" required="true" />
                </div>

                <div>
                    <lightning:select aura:id="type1" value ="{!v.RFQObj.Product_Groups__c}" name="select1" label="Product Group" required="true" messageWhenValueMissing="Please select Product Group">
                        <option value="">None</option>
                        <aura:iteration items="{!v.productgroup}" var="item">
                            <option value="{!item}">{!item}</option>
                        </aura:iteration>
                    </lightning:select>
                    <span style="color: #C23930;font-size: .75rem;">{!v.ErrorMessage3}</span>
                </div>

            </div>
        </lightning:recordEditForm>

JS Controller:

({ doInit: function(component, event, helper) {

    //fetch product group picklist values
    var action = component.get("c.getProductGroup");
    action.setCallback(this, function(response) {
        if (response.getState() == "SUCCESS") {

            var response=response.getReturnValue();
            component.set('v.productgroup',response);
        }
    });

    component.find("ReceivedDate").set("v.value"," "); 
}

here I am trying to set the ReceivedDate as null, however I am getting an error "cannot read property 'set' of undefined".

What could be the issue?

1 Answer 1

0

Since the block you are trying to access is within record edit form, try to clear the value in on load method which you have defined that is "handleOnload". The reason why you are not able to find the element because, it may not be rendered yet.

    handleOnload: function(component, event, helper){
        component.find("ReceivedDate").set("v.value"," ");
}

Also you have not enqueued the action yet in your controller, or probably you have not mentioned that part.

You must log in to answer this question.

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