I'm trying to bind the aura:attribute 'newAccount' name field to dynamically created component aura:inputText field, code below:
MyComponent.cmp
<aura:component>
<aura:attribute name="newAccount" type="Account"
default="{'sobjectType':'Account', 'Name':'My New Account'}"/>
<aura:handler name="init" value="{!this}" action="{!c.renderLayout}"/>
<div class="container">
{!v.body}
</div>
</aura:component>
MyComponentController.js
({
renderLayout: function(component, event, helper){
var thenewAccount = component.get('v.newAccount');
$A.createComponent(
"ui:inputText",
{
"aura:Id":"accountName",
"class": "form-control",
"value": "{!v.newAccount.Name}",
"label": "Account Name"
},
function(newItem){
//Add the new input to the body array
if (component.isValid()) {
var body = component.get("v.body");
body.push(newItem);
component.set("v.body", body);
}
}
);
}
})
But unfortunately, the binding is not working as expected when I create input field dynamically. Is there something wrong with my code, Is there any code change I can do to make it work?
Edited:
Updated component 'renderLayout' invocation as @crmprogdev suggested. I missed it initially but still the input field is being generated but the binding is not working.