I have found that not having default attributes can cause problems with binding.
UPDATE - this applies to ALL attributes, including the sobjectType and CloseDate .
Add all attributes (even if empty at this stage) that you want to write to the server, because if they are not at least initialised in the defaults area, they don't get sent.
Also there are perhaps some missing fields that are needed for the Opportunity to deserialize properly (in the internal deserialization routine that is called prior to passing it to your @AuraEnabled
method).
So perhaps you could define your oppty attribute like this:
<aura:attribute name="opportunity"
type="Opportunity"
default="{ 'sobjectType': 'Opportunity',
'Name': 'New Opportunity',
'StageName': 'Initial Contact',
'CloseDate':'2016-08-01'} />
Or at least set the name and stage prior to passing it to your method.
Of course, you may be doing this already - I can't see what your console output is.
This is just a long shot, because you seem to have done everything else right.
The solution is to declare an event instead of an attribute when you want to provide a callback. Below is myButton.cmp rewritten to use events.
pressEvent.evt
<aura:event type="COMPONENT" />
myButton.cmp
<aura:component>
<aura:attribute name="label" required="true" type="String" />
<aura:attribute name="class" required="false" type="String" />
<!-- Declare an "instance" of pressEvent -->
<aura:registerEvent name="press" type="c:pressEvent"/>
<input type="button" value="{!v.label}" class="{!v.class}" onclick="{!c.onClick}" />
</aura:component>
myButtonController.js
({
onClick : function(component, event, helper) {
helper.trackButtonClick(component, event);
var event = component.getEvent('press');
event.fire();
}
})
This wasn't clear from the documentation, but there are two ways to handle an event. The first is to use the <aura:handler />
markup. To handle the press event of myButton, you could do this:
<aura:handler name="press" event="c:pressEvent" action="{!c.onOk}"/>
I would avoid this approach because if you have more than one button, the press event for all of them would be handled by the same action c.onOk
.
The second way to handle an event is to pass a callback as an attribute in the <c:myButton />
markup. I didn't see this in the Salesforce docs but found it in an unrelated question. This is exactly what I needed. Each instance of myButton gets a unique callback.
myButtonConsumer.cmp
<aura:component>
<!-- No aura:handler necessary. Just pass the callback as an attribute -->
<!--<aura:handler name="press" event="c:pressEvent" action="{!c.onOk}"/>-->
<c:myButton label="OK" class="slds-button" press="{!c.onOk}" />
<c:myButton label="Cancel" class="slds-button" press="{!c.onCancel}" />
</aura:component>
myButtonConsumerController.js
({
onOk: function(component, event) {
alert('OK pressed!');
},
onCancel: function(component, event) {
alert('Cancel pressed!');
}
})
Best Answer
This is not currently possible. The datasource attribute of the design file only supports a static list of values.
Providing dynamic picklist support is on our roadmap, but there is no timeline to share at this point [#safeharbor].