I've seen that since Spring'15, there are new standard components available in Lightning.
I've been looking for a component that would be a sort of apex:inputField
, but in Lightning. The force:inputField
component seems to be what I want, however I was not able to make it work.
The component is available inside the Documentation App (/auradocs/reference.app), but there is nothing about it inside the Spring'15 Release Notes so I wonder if this component is fully available or not.
I wrote a really basic test to display an Account Name. I've set the attribute type to Account, using type="Account"
in my aura:attribute
tag but that is not working. Maybe am I missing something about the correct way to set it ?
Here is my code :
LIGTHNING COMPONENT
<aura:component controller="[YOURNAMESPACE].AccountController" implements="force:appHostable">
<aura:attribute name="account" type="Account"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}" />
<force:inputField value="{!v.account.Name}" />
</aura:component>
COMPONENT CONTROLLER
({
doInit: function(component, evt, helper) {
var action = component.get("c.getAccount");
action.setCallback(this, function(a) {
component.set("v.account", a.getReturnValue());
});
$A.enqueueAction(action);
},
})
APEX CONTROLLER
public class AccountController {
@AuraEnabled
public static Account getAccount() {
return [select Id, Name from Account Limit 1];
}
}
However, using <ui:inputText value="{!v.account.Name}" />
instead of <force:inputField value="{!v.account.Name}" />
is working.
Did someone manage to use it ?
apex:inputField
VF tag, you'd need to bind it to something that was a field of an sObject, not just plain-old data in some JS property or random JSON object. Can you try binding it to a component attribute that is some sObject type and give it a go. If I have a chance to try tomorrow, I'll give it a go, too as I am curious.