Blog for Learning

| lesson material | material summary | questions and answers | definitions | types and examples | other information | materi pelajaran | ringkasan materi | pertanyaan dan jawaban | definisi | jenis-jenis dan contoh-contoh | informasi lainnya |

Powered by Blogger.

Pages

How to Change the HTML5 Validator Language into Indonesian

HTM 5 Tutorial Validator
Input validation is very important to prevent errors in input values.
For example:
If there is a field that is still empty, the message will appear, the data is still empty .
In the past, we validated the input using Javascript.
Now it's no longer there.
Because HTML 5 already provides attributes that we can use for validation.
However, the language used is English. (Depending on the location settings in the browser)
What if we want to change it to Indonesian only?
Then we must override the validation message with Javascript.

Javascript Function to Change Validation Message

We use JQuery, here is the code:
$("form input[type=text]").on("change invalid", function() {
    var textfield = $(this).get(0);
    
    // hapus dulu pesan yang sudah ada
    textfield.setCustomValidity("");
    
    if (!textfield.validity.valid) {
      textfield.setCustomValidity("Tidak boleh kosong!");  
    }
});
The code will be executed during the event changeand invalid.
Then change the text validation by method setCustomValidity().
In the above code, we select all tags <input>.
If you want to select other elements, like <textarea>, then we can add the selector like this:
$('form input[type=text], form textarea').on('change invalid', function() {
    //… 
}

Demo


0 Komentar untuk "How to Change the HTML5 Validator Language into Indonesian"

Silahkan berkomentar sesuai artikel

 
Template By Kunci Dunia
Back To Top