I have a requirement where user needs to create a new Opportunity record in a lightning popup.Here I have to display a Territory field which is a lookup .So I am using lightning:inputField
tag for this within lightning:recordEditForm
.
<lightning:inputField aura:id="Territory" fieldName="Territory__c" required="true"/>
But now user wants to have a default territory to be shown on initial loading. If they dont want the default territory, they can change that value. So in order to show default value I have added value field in lightning:inputField
<lightning:inputField aura:id="Territory" fieldName="Territory__c" value="{!v.defaultTerritory}" required="true"/>
defaultTerritory --> Assigning it from backend on loading.
Now if I try to save the Opportunity with default territory, the JSON record passed from lightning to apex is
{"sobjectType":"Opportunity","Name":"Jan 2201-1","AccountId":"00X0j00000KGXXXXXX","Territory__c":"a0X0j000000nXXXXXX","CurrencyIsoCode":"JPY","OwnerId":"00Xf100000HIuXXXX"}
If I change from default territory to new territory in lookup , on saving the JSON record passed is,
{"sobjectType":"Opportunity","Name":"Jan 2201-1","AccountId":"00X0j00000KGXXXXXX","Territory__c":["a0X0j000000nXXXXXX"],"CurrencyIsoCode":"JPY","OwnerId":"00Xf100000HIuXXXX"}
The territory Id is enclosed within a square bracket[].
Could anyone please let me know what is the mistake I am doing.Why [] is getting added while changing territory and how to resolve it.
v.defaultTerritory
?save
function implemented?