0

Controller

init : function(component, event, helper) {
    //get record type id
    var reportType = component.get("v.pageReference").state.recordTypeId;
    console.log(component.get("v.pageReference").state.recordTypeId);
    //save into the attribute
    component.set("v.recordTypeId", reportType);
    console.log('Fields');
    console.log(component.find('salesProjectForm'));
    console.log(event.getParam('fields'));
},

formSuccess : function(component, event, helper) {
    var toastEvent = $A.get("e.force:showToast");  
    toastEvent.setParams({  
      "title": "Success!",  
      "message": "Record is successfully created!",  
      "type": "success"  
    });  
    toastEvent.fire();
},

handleOnLoad : function(component, event, helper) {
    console.log("handleOnLoad");
    var record = event.getParam('record');
    console.log(JSON.stringify(record));
    // I've noticed this will fire multiple times. If you don't set some criteria 
// to protect against it, this workaround will result in an infinite loop
if(record !== undefined && !record.fields.Name.value){

    // I did not test if setting both value and displayValue attributes are required
    record.fields.Name.display = false;
    event.setParam('record', record);
    }
},

handleSubmit : function(component, event, helper) {
    event.preventDefault(); // stop form submission
    var eventFields = event.getParam("fields");
    console.log('handlesubmit');
    eventFields["Name"] = "Test Value";
    component.find('myfsalesProjectFormorm').submit(eventFields);
}

HTML

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId,lightning:actionOverride,lightning:hasPageReference" access="global">
<aura:attribute name="recordTypeId" type="Id"/>
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:card iconName="custom:custom19" title="lightning:recordForm">
    <div class="slds-p-left_large slds-p-right_medium"> 
        <lightning:recordForm
            aura:id="salesProjectForm"
            objectApiName="Opportunity"
            layoutType="Full"
            columns="2"
            recordTypeId="{!v.recordTypeId}"
            onsubmit="{!c.handleSubmit}"
            onsuccess="{!c.formSuccess}"
            onload="{!c.handleOnLoad}"/>
    </div>
</lightning:card>

4
  • so you want assign a value to field before form submit?
    – sdandamud1
    Jul 2, 2019 at 13:24
  • @sdandamud1 I want to assign a value toa field before submit, thats correct. But, i also want make that field invisible to the user Jul 3, 2019 at 9:58
  • Add the field in lightning:recordformthen add class slds-hide for that field?
    – sdandamud1
    Jul 3, 2019 at 10:34
  • how can i had slds-hide to that field? Jul 4, 2019 at 12:37

0

Browse other questions tagged .