I am trying to set a validation on a dynamic lightning:inputfield bus this is not working neighter do I get an error. I think my binding isn't correct.
Component
<aura:iteration items="{!v.fields}" var="field" >
<aura:if isTrue="{!v.inputModeBool == true? true: false}">
<lightning:inputField fieldName="{!field.fieldPath}" aura:id="{!field.fieldPath}"/>{!field.required}
</aura:if>
<aura:if isTrue="{!v.inputModeBool != true? true: false}">
<lightning:layout >
<lightning:layoutitem size="10">
<lightning:outputField fieldName="{!field.fieldPath}"/>
</lightning:layoutitem>
<lightning:layoutitem size="2">
<lightning:buttonIcon iconName="utility:edit" variant="bare"
alternativeText="edit"
onclick="{!c.next}"/>
</lightning:layoutitem>
</lightning:layout>
</aura:if>
</aura:iteration>
Controller
next: function(component, event, helper) {
alert('Whoohooo');
var invalidFields = helper.isFormValid(component);
if(invalidFields && invalidFields.length > 0){
helper.reportUserError(
'Please complete all required fields',
'Incomplete: '+ invalidFields.join(', ')
);
event.preventDefault();
return;
}
},
Helper
isFormValid: function (component) {
return (component.find('field.fieldPath') || [])
.filter(function (i) {
var value = i.get('v.value');
return !value || value == '' || value.trim().length === 0;
})
.map(function (i) {
return i.get('v.fieldName');
});
}