0

I'm using lightning:recordEditForm for users to change values on a specific record.

The form looks like this:

<lightning:recordEditForm aura:id="form"
                                  onsubmit="{!c.handleSubmit}"
                                  onsuccess="{!c.handleSuccess}"
                                  onerror="{!c.handleError}"
                                  recordId="{!v.recordId}"
                                  objectApiName="MyCustomObject">
            <lightning:messages />
            <lightning:inputField 
                fieldName="Start__c" 
                aura:id="start" 
                />
            <lightning:inputField 
                fieldName="End__c" 
                aura:id="end" 
                />

I know that with ui:inputText there is a way to get the old value and new value with event.getParam("oldValue") and event.getParam("value") but this does not seem to be supported with lightning:inputField.

Is there any way for me to use an onchange handler on the lightning:inputField to track oldValue and newValue?

0

Inputfield does support onchage events, so, on field change you can bind the value to an attribute, to which you can add an handler for change:

component.cmp

<aura:handler name="change" value="{!v.item}" action="{!c.itemsChange}"/>
<aura:attribute name="item" type="String"/>

<lightning:recordEditForm
        objectApiName="todos__c">
        <!-- the messages component is for error messages -->
        <lightning:messages />

        <lightning:inputField fieldName="Name" onchange="{!c.change}"/>
        <lightning:inputField fieldName="type__c" />
        <lightning:inputField fieldName="completed__c" />
        <div class="slds-m-top_medium">
            <lightning:button disabled="{!v.disabled}" variant="brand" type="submit" name="save" label="Save" />
        </div>
    </lightning:recordEditForm>

controller.js

change : function(component, event, helper) {
    var value = event.getParam("value");
    component.set('v.item', value)
},
itemsChange : function(component, event, helper) {
    var newValue = event.getParam("value");
    var oldValue = event.getParam("oldValue");
},

Its a bit tedious to have to add an extra step, but you can manage this way and have old/new values.

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.