I am loading my fields dynamically trough a fieldset. Using aura:id="requiredField" on the lightning:inputField I can get the fields using a map in the controller. I have made some fields required at fieldset level not at fieldlevel. How can I get these values in the controller to validate only on the required fields? Or how can I get the attributes for a specific field. Using required is returning empty.
Component
<lightning:card title="{!v.title}" iconName="{!v.iconName}" class="slds-p-around--none">
<lightning:recordEditForm aura:id="recordViewForm"
recordId="{!v.recordId}"
objectApiName="{!v.genericObject}"
onsubmit="{!c.fireRefreshView}"
onerror="{!c.handleError}"
class="slds-p-around--small">
<lightning:messages />
<aura:iteration items="{!v.fields}" var="field">
<aura:if isTrue="{!v.inputModeBool == true? true: false}">
<lightning:inputField fieldName="{!field.fieldPath}" aura:id="requiredField" />{!field.required} <!-- class="customRequired"-->
Controller
next: function (component, event, helper) {
var recUi = component.get('v.recordId');
alert('recUi: '+recUi);
var Fields = component.find('requiredField').map(function (i) {
return i.get('v.fieldName') });
alert('Fields: '+Fields);
var FieldValue = component.find('requiredField').map(function (i) {
return i.get('v.value'); });
alert('FieldValue: '+FieldValue);
var FieldRequired = component.find('requiredField').map(function (i) {
return i.get('v.required'); });
alert('FieldRequired: '+FieldRequired);
Best Answer
Try as below (main point is having custom class and styling it). Also for validations, you need iterate over all fields and check which are required, and then check if that field has value
Aura comp:
JS:
Styles:
Apex class method: