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
Kashish Bansal 39Kashish Bansal 39 

Explain this in detail

let validExpense = component.find('expenseform').reduce(function (validSoFar, inputCmp) {
inputCmp.showHelpMessageIfInvalid();
return validSoFar && inputCmp.get('v.validity').valid; }, true);
Best Answer chosen by Kashish Bansal 39
Suraj Tripathi 47Suraj Tripathi 47
Hi Kashish,
Greetings!!

inputCmp.showHelpMessageIfInvalid(); this function is used to check if the element is valid or not, if the element is not valid then it will be showing the help message and also the red border around the field which is invalid.

and coming to the third line i.e return validSoFar && inputCmp.get('v.validity').valid; }, true); is basically a if and condition, So in this case, (v.validity).valid , the condition is checking that, the component is in vaid state or not.

Here is the reference link-
https://sfdctechie.wordpress.com/2019/01/29/understanding-reduce-and-showhelpmessageifinvalid-js-controller-methods/


Please mark it as the best answer if it helps you to fix the issue.
Thank you!
Regards,
Suraj Tripathi 

All Answers

AbhinavAbhinav (Salesforce Developers) 
Hi Kashish,

Please refer below link which explain your question in details:
https://sfdctechie.wordpress.com/2019/01/29/understanding-reduce-and-showhelpmessageifinvalid-js-controller-methods/

Hope above answer was helpful, Please mark as best answer so that it can help others in future.

Thanks!
Suraj Tripathi 47Suraj Tripathi 47
Hi Kashish,
Greetings!!

inputCmp.showHelpMessageIfInvalid(); this function is used to check if the element is valid or not, if the element is not valid then it will be showing the help message and also the red border around the field which is invalid.

and coming to the third line i.e return validSoFar && inputCmp.get('v.validity').valid; }, true); is basically a if and condition, So in this case, (v.validity).valid , the condition is checking that, the component is in vaid state or not.

Here is the reference link-
https://sfdctechie.wordpress.com/2019/01/29/understanding-reduce-and-showhelpmessageifinvalid-js-controller-methods/


Please mark it as the best answer if it helps you to fix the issue.
Thank you!
Regards,
Suraj Tripathi 
This was selected as the best answer