I have a lightning component (Summer 16) which contains a "Task" attribute as follows:
<aura:attribute name="task" type="Task" default="{ 'sobjectType': 'Task' }"/>
Further down the page, I have a force:inputField to allow the user to select the owner of the task as follows:
<force:inputField value="{!v.task.OwnerId}" aura:id="OwnerId" />
This works great and allows me to select a user the lightning way.
However, I'd like to default this to the current user. I have tried setting it in the init event with no luck. The init event is firing, and I have retrieved the value after setting it and it is there. Static user id used for testing purposes only and it is a valid user id in our org.
init: function(component, event, helper) {
var tska = component.get("v.task");
tska.OwnerId = '0054B000000XxeH';
component.set("v.task", tska);
}
I have also tried this code in the init method with no luck:
component.find("OwnerId").set("v.value", "00561000001ZISx");
Now, if I create the attribute as follows, it does show it correctly:
<aura:attribute name="task" type="Task" default="{ 'sobjectType': 'Task' , 'OwnerId': '0054B000000XxeH' }"/>
I tried setting the default dynamically with no luck. Any idea if this is possible? Thanks!
Best Answer
Both the OwnerId and the Owner need to be populated...
but you also need to manually set some values on the force:inputField to get it to display the Pill (this assumes the force:inputField has an aura:id="taskOwnerId")...
I'm not sure if this is supported but its working for me.