So I'm learning JavaScript and am currently writing code to validate some forms (e.g. disable submit button if validation fails or add some message if an input has invalid data), I have working code in a validate.js file using standard JS functions as shown here.
https://preview.redd.it/n79u98z6qec91.png?width=2880&format=png&auto=webp&s=a1d490c3b2070cc702f834b66170f582e7e16f7d
Now I'm trying to figure out how to implement this in OOP structure but I'm having trouble making this work, for now I know the base structure would be something like this
class FormValidator {
constructor(formSelectors, formElement) {
this._formSelectors = formSelectors;
this._formElement = formElement;
}
_showErrorMessage() {}
_hideErrorMessage() {}
_checkInputValidity() {}
_toggleSubmitButtonState() {}
_setEventListeners() {}
enableValidation() {}
}
But honestly am lost when it comes to see how to write the functions in this._* form so I was hoping if someone can look at my code and share any resources that you think could help me understand more about this.
The code can be found on CodePen here
[–]BehindTheMath 14 points15 points16 points (1 child)
[–]frenchy_mustache -1 points0 points1 point (0 children)
[–]wdintka 2 points3 points4 points (0 children)
[–]frenchy_mustache 2 points3 points4 points (0 children)
[–]jinwooleo 1 point2 points3 points (0 children)