I need to display custom object field inputs on Lightning component. This has to support localization.
My code looks like this:
<aura:attribute name="myFieldsMap" type="Map" default="{ 'Field1__c': 'Field 1 label', 'Field2__c': 'Field 2 label', }" />
<aura:attribute name="myObject" type="myObject__c" />
<lightning:input label="{!v.myFieldsMap.Field1__c}" value="v.myObject.Field1__c" />
<lightning:input label="{!v.myFieldsMap.Field2__c}" value="v.myObject.Field2__c" />
I get labels in apex using DescribeFieldResult
and return values to component.
force:inputField
is not rendered for some reason and I don't want to investigate why (Lightning Component - force:inputField not rendering)
What I don't like in this solution is that I have to specify default
value for map with all fields I am using, because if label value is empty, component throws an error. For adding new fields I just want to populate lightning:input
. Unfortunately I also have to add field definition to list in Apex to get the label, but specifying default
makes this messy. Is there more elegant way than this?