I am building a validator using a Builder Pattern. Not sure if I am using the correct pattern but I keep on having Javascript uncaught type error is not a function although my codes works.
Full Error msg:
Uncaught TypeError: validate.IsTCAgree(...).IsRMGTCAgree is not a function
at HTMLButtonElement.<anonymous> (TPR:1846:115)
at HTMLButtonElement.dispatch (jquery-3.5.1.js:5429:27)
at HTMLButtonElement.elemData.handle (jquery-3.5.1.js:5233:28)
$btnSubmit.click(function(e) {
var validate = new ValidatorTnCBuilder($btnSubmitErrMsg);
if (validate.IsTCAgree('Please check Terms and Conditions.').IsRMGTCAgree('Please check
agreement.
')) {
// do sth
}
});
const ValidatorTnCBuilder = function($el) {
return {
IsTCAgree: function(msg) {
if (!$checkIsTCAgree.is(':checked')) {
$el.text(msg);
return false;
}
return this;
},
IsRMGTCAgree: function(msg) {
if (!$checkIsRMGTCAgree.is(':checked')) {
$el.text(msg);
return false;
}
return this;
}
}
}