Created
August 30, 2019 11:34
-
-
Save Alexisgt01/405c6caec5ee8f44f99ae22bfb99e359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var counter = function(e, nb = 50, inverse = false) { | |
var span = e.nextSibling.nextSibling | |
var parent = e.parentNode.parentNode | |
if (inverse == false) { | |
span.innerText = e.value.length + '/' + nb + ' caractères restant' | |
if (e.value.length > nb || e.value.length == 0) { | |
parent.classList.add('has-error') | |
parent.classList.remove('has-success') | |
} else { | |
parent.classList.remove('has-error') | |
parent.classList.add('has-success') | |
} | |
} else { | |
span.innerText = e.value.length + '/' + nb + ' caractères requis' | |
if (e.value.length < nb) { | |
parent.classList.add('has-error') | |
parent.classList.remove('has-success') | |
} else { | |
parent.classList.remove('has-error') | |
parent.classList.add('has-success') | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<style> | |
.has-error .help-block { color: #dc3545 !important; } | |
.has-success .help-block { color: #28a745 !important; } | |
</style> | |
<div class="form-group"> | |
<label>Pseudo</label> | |
<div class="col"> | |
<input type="text" onKeyUp="counter(this, 100)"> | |
<span class="help-block"></span> | |
</div> | |
</div> | |
<div class="form-group"> | |
<label>Password</label> | |
<div class="col"> | |
<input type="password" onKeyUp="counter(this, 8, true)"> | |
<span class="help-block"></span> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment