Background
I have a lightning component with a lightning:recordEditForm
for creating new Opportunity
records.
The lightning:recordEditForm
contains many lightning:inputField
's
I would like to perform basic required field validation on the form, using code like this:
let isValid = true;
let fields = cmp.find("requiredField"); // gets all required fields
for (var i = 0; i < fields.length; i++) {
if (fields[i] != null) {
if (fields[i].get('v.validity').valid == false) {
fields[i].showHelpMessageIfInvalid();
isValid = false;
}
}
}
But I am unable to access property validity
/ valid
on the lightning:inputField
And I am unable to call the showHelpMessageIfInvalid()
method on the lightning:inputField
Questions
- How should I approach form validation using
lightning:recordEditForm
- How can I get each field to display the red border if the field is not valid?