I have a task to prevent users from typing "%" in a textArea, so I implemented the following:
However, even after clicking inside the text area, I can still type '%', indicating that my onkeypress function is not working properly or there is an issue with the function itself.
$scope.test = function() {
var txtarea = document.getElementById("exampleFormControlTextarea1");
txtarea.addEventListener("input", function() {
txtarea.value = txtarea.value.replaceAll("%", "");
})
}
I also tried another approach:
function myfunction () {
var txtarea = document.getElementById("exampleFormControlTextarea1");
txtarea.addEventListener("input", function() {
txtarea.value = txtarea.value.replaceAll("%", "");
})
}
<div class="col-md-12 label-base">
<label for="exampleFormControlTextarea1">Justify</label>
<textarea style="resize: none" ng-disabled="negociacaoEspecCtrl.proposta.flagDesabilitaEdicaoProposta"
class="form-control observacoes" id="exampleFormControlTextarea1" rows="3"
ng-model="negociacaoEspecCtrl.proposta.dadosCadastro.negociacaoEspecial.justificativaNegociacaoEspecial"
onkeypress="test()"></textarea>
</div>