• AnirudhRdy
  • NEWBIE
  • 10 Points
  • Member since 2020

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 1
    Replies
Hi All,

I have been trying to get the value of a lightning:inputfield into controller.js but when I try to get the value it is coming as undefined.

Code:

Component:
<aura:component implements="force:hasRecordId,lightning:actionOverride,force:appHostable,force:hasRecordId,force:hasSObjectName,flexipage:availableForRecordHome,flexipage:availableForAllPageTypes,forceCommunity:availableForAllPageTypes," access="global"> 

 <aura:attribute name="ServiceRequestRecordFields" type="WorkOrder"/>
  <force:recordData aura:id="recordEditor"
                      layoutType="FULL"
                      targetError="{!v.recordError}"
                      targetRecord="{!v.ServiceRequestRecord}"
                      targetFields ="{!v.ServiceRequestRecordFields}"
                      mode="EDIT"/>

<lightning:input aura:id="shopWrkId" label="Shop Work Order" value="{!v.ServiceRequestRecordFields.Shop_Work_Order__c}" onchange="{!c.CheckLength}"/>

</aura:component>

Controller.js:
 CheckLength : function(component, event, helper) {
        var val = component.find("shopWrkId").get('v.value');
         console.log('shopWrkId'+val);
        if(val.length > 20){
            var comp = component.find("number");
            comp.set('v.value',val.substring(0,20));
        }
    },

Now in the console value is coming as undefined. Please note that this is happening only with this particular field and when I change the field to a different one it is working as expected. Can anyone please help with this.

Two Fields:
Shop_Work_Order__c : Datatype: Text ; Length: 20 => not working
EVL_Customer__c: Datatype: Text ; Length: 250 => Working

Thanks,
Anirudh