1

I keep getting $A.getCallback() [Cannot read property of null when I start typing in the text fields of a form. Before adding the default I have the component as below:

<aura:component description="AddBoatReview">
<aura:attribute name="boat" type="boat__c"/>
<aura:attribute name="boatReview" type="BoatReview__c" access="private"/>
    <aura:attribute name="recordRecord" type="String" access="private"/>
    <aura:attribute name="recordSaveError" type="String" access="private"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <!-- <force:recordData aura:id="service"
                      layoutType="FULL"
                      recordId="{!v.boatReview.Id}"
                      fields="Id, Name, Comment__c, Boat__c"
                      targetError="{!v.recordSaveError}"
                      targetRecord="{!v.recordRecord}"
                      targetFields="{!v.boatReview}"
                      mode="EDIT"
                      recordUpdated="{!c.onRecordUpdated}"/> -->

    <form class="slds-form--stacked">
        <lightning:input aura:id="boatRevw" label="Title"
                         value="{!v.boatReview.Name}"/>
        <lightning:inputRichText aura:id="boatRevw" title="Description"
                         value="{!v.boatReview.Comment__c}"/>
        <lightning:button label="Submit"
                          class="slds-m-top--medium"
                          iconName="utility:save"
                          variant="brand"
                          onclick="{!c.onSave}"/>
    </form>
</aura:component>

Controller:

({
    doInit:function (component,event,helper) {
        var eventParams = event.getParams();
        helper.onInit(component,eventParams);
    },
    onRecordUpdated:function (component,event,helper) {

    },
    onSave:function (component,event,helper) {
        console.log('Enters the Save method');
        var recordData = component.find("service");
    }

})

Helper does nothing, just have a onInit sitting there.

I get the below error when I type a letter in text fields:

enter image description here

I referred this link - Lightning - Error in $A.getCallback() to see if this solves the problem, I do not have an apex class yet and I try to add the default values for the boatReview attribute. default="{'sobjectType:'BoatReview__c','Name':'','Comment__c':''}" Which gave the error on page load:

enter image description here

1 Answer 1

5

Edit: lightning:input has label and name as required attribute.

<lightning:input 
     aura:id="boatRevw" 
     label="Title"
     name="Title"
     value="{!v.boatReview.Name}"/>

Your boatReview attribute is null. You need to assign a default value to it as I guess you want to take fresh input and not displaying data from server in edit mode.

<aura:attribute 
        name="boatReview" 
        type="BoatReview__c" 
        access="private" 
        default="{'sobjectType':'BoatReview__c', 'Name':'', 'Comment__c':''}"/>

For a quick check, you can comment the <form> and your page should load without error but form content will not render.

3
  • My bad, I missed default="{'sobjectType a single quote - syntax error.
    – Arnold
    Commented Dec 26, 2017 at 21:10
  • @Arnold Did fixing default JSON alone worked? Because I was getting error until I added name for the lightning:input Commented Dec 26, 2017 at 22:01
  • Default alone worked!
    – Arnold
    Commented Dec 26, 2017 at 22:03

You must log in to answer this question.

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