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

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.

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

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.