I want to modify the error message displayed when an invalid email is entered, but I am unable to access the source code.
I believe the source code triggers setCustomValidity based on the appearance of the error message. Here is the relevant element:
<input type="email" value="" name="customer[email]" id="email" class="large" size="30">
The only way I can make changes is by using external JavaScript or CSS files.
There are two approaches I'm considering:
Solution 1: Adding inline HTML elements with JavaScript to achieve something like this:
<input type="email" value="" name="customer[email]" class="large" size="30" oninvalid="this.setCustomValidity('Please Enter valid email')" oninput="setCustomValidity('')">
As a newcomer to JS, I'm struggling with implementing HTML in an external JS file.
Solution 2: Calling the oninvalid and setCustomValidity DOM methods in error_message.js
like this:
function emailValidity(){
var myInput = document.getElementByName("customer[email]");
myInput.oninvalid = function() {
(errorMessage)
};
function errorMessage(){
myInput.setCustomValidity("hey! the email isn't right");
}
}
However, even after including this file, it still doesn't change the default error message!
Any assistance would be greatly appreciated. Thank you in advance.