1

I have a lightning component that uses force:inputField for a handful of Contact fields in a form in a Partner Community so that a logged in user can update their contact info. It appears that if the field did not previously have the value (eg. the "Title" field is null when the page loads) then it won't let me add a value. However in the Sandbox I can.

I have the page set up like this (abbreviated for clarity):

<aura:component controller="CommunityController" access="global">
   <aura:attribute name="contactId" type="Id" />
   <aura:attribute name="contactRecord" type="Contact" default="{ 'sobjectType': 'Contact' }"/>

   <force:inputField value="{!v.contactRecord.Title}" class="inputFeild"/>
   <ui:button class="slds-button slds-button--brand" label="Save" press="{!c.saveContactRecord}"/>
</aura:component>

So in the sandbox, if I load this component and the Contact did not have a Title, I can add one and when I submit the form, I can do console.log(component.get('v.contactRecord)); and I see that the contact has a value set to what I entered.

In Production, when I do the same, the Title attribute does not appear on the contact. HOWEVER, if the Title has a value when the component is loaded, I AM able to change the existing value in Production...

Is this another force:inputField bug?

EDIT: This appears to also happen with regular ui:inputText and other ui tags. If the value isn't set when the page loads, then it's not letting me set a value and send it back to apex. Again, this also works in sandbox but not in Production.

1 Answer 1

1

Is locker service turned on in production?. With locker service every sobject field you instantiate needs to explicitly mentioned in default if its a new contact record.This is how salesforce checks the fields you access has been provided access through the profile.

If its an existing record and if the title is not present in the contact record then the SOQL will not return the field in the first place since its value is null.

In this case if {!v.contactRecord.Title} does not have a value then the title attribute will not be sent to your client side controller when you make server call.

To overcome that , what you can do is have a default contact definition attribute like below with all fields you need to use in your component.

  <aura:attribute name="Contactdef" type="Contact" default="{'sobjectType': 'Contact','LastName': '','title':''}" access="Public"/>

You have the below data attribute

 <aura:attribute name="contactRecord" type="Contact" default="{ 'sobjectType': 'Contact' }"/>

Once you get the data back from server you can call a function which will check if all the attributes you need is present in your data object. If not it will merge them and give you one complete object for UI. Below is the function

//obj1 - dataformatobject , obj2 - actual data object
merge : function(obj1, obj2){        
    var obj3 = {};
    var attrname;
    for (attrname in obj1) { obj3[attrname] = obj1[attrname]; }
    for (attrname in obj2) { obj3[attrname] = obj2[attrname]; }
    return obj3;
}

All we are doing in this function is to add all the attributes which are not part of the object that was returned from server to that object to ensure we are able to collect data from them.

Hope this helps!

You must log in to answer this question.

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