function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kalpesh Vyas 14Kalpesh Vyas 14 

I wish to understand this validation example in lightning

I wish to understand this validation example in lightning

https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service_example.htm

In this example I want to understand "validateContactForm" method specially below part
What is this "reduce" and "showHelpMessageIfInvalid" do, any other reference help to understand it?
// Show error messages if required fields are blank
        var allValid = component.find('contactField').reduce(function (validFields, inputCmp) {
            inputCmp.showHelpMessageIfInvalid();
            return validFields && inputCmp.get('v.validity').valid;
        }, true);

 
Best Answer chosen by Kalpesh Vyas 14
Kalpesh Vyas 14Kalpesh Vyas 14
I got answer here..
https://salesforce.stackexchange.com/questions/184525/help-me-to-undestand-this-lightning-helper-methods-reduce-showhelpmessageifin/184535
 

All Answers

Kalpesh Vyas 14Kalpesh Vyas 14
I got answer here..
https://salesforce.stackexchange.com/questions/184525/help-me-to-undestand-this-lightning-helper-methods-reduce-showhelpmessageifin/184535
 
This was selected as the best answer
Manjeet Singh 17Manjeet Singh 17
It checks if all the fields in the Lightning component forms are valid entry or not. Reduce is a javascipt function which is applied to and array object and take a function parameter which in turn has two parameters.Second is all the entry in the array. First is the total result of the all recursive calls to the function(validFields, inputCmp). InputCmp.showHelpMessageIfInvalid() shows message at the bottom of field like an error message.