0

Below is my code

<aura:attribute name="newModule" type="Module__c" default="{'sobjectType' : 'Module__c',
                                                                   'StartDate__c':'',
                                                                   'EndDate__c' : '',
                                                                   'Name' : ''}"/>
    <aura:attribute name="ProgramId" type="Id" />

    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:method name="ResetChild" action="{!c.handleReset}"/>



    <lightning:recordEditForm aura:id="NewModulePopUp" objectApiName="Module__c" onsubmit="{!c.createNewController}" 
                              onsuccess="{!c.showSuccess}" onerror="{!c.showError}">
    <lightning:messages />

        <lightning:inputField aura:id="namefield" fieldName="Name" value="{!v.newModule.Name}" />
        <lightning:inputField fieldName="ModuleType__c" value="{!v.newModule.ModuleType__c}"/>
        <lightning:inputField fieldName="ModuleStatus__c" value="{!v.newModule.ModuleStatus__c}"/>

        <lightning:button label="Create Module"  variant="brand" type="submit" name="createmodule"/>
    </lightning:recordEditForm>

Below is my Controller

 createNewController : function(component, event, helper){

            var action = component.get("c.createNewModule");
            console.log('MName' +component.get("v.newModule").Name); --> THIS IS BLANK
    }

why is object binding not working here? Is something wrong? Request to help.

Thanks in advance!

3

You cannot use lightning:recordEditForm as you are trying to do.

First of all you have to enter recordId attribute in it, for editing a record, (without recordId for a new record), try reading the docs for understanding how to write this.

Second - you do not need to set the value attribute for each lightning:inputField - the values will auto-populate after you add the recordId attribute to the lightning:recordEditForm component.

Third - in your controller, if you want to get a value or set a value from code, you should do like this:

doInit : function(component, event, helper){
    // get value
    var nameValue = component.find("v.namefield").get("v.value");
    console.log(nameValue);
    // set value
    component.find("namefield").set("v.value", "new value to set");
}
| improve this answer | |
  • I have a similar requirement but I want to set the field every time user clicks a button. With this code the button works fine as long as the user has not updated the field manually, else it doesn't works – Monalisa Das Nov 5 '18 at 12:49
  • please post a different question about that – Itai Shmida Nov 5 '18 at 12:52
  • Yeah I've posted - salesforce.stackexchange.com/questions/238379/… – Monalisa Das Nov 5 '18 at 12:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.