You need to sign in to do that
Don't have an account?
Kashish 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);
inputCmp.showHelpMessageIfInvalid();
return validSoFar && inputCmp.get('v.validity').valid; }, true);
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
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!
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