Disable input of certain characters in text area

  angularjs, controller, javascript, textarea

So i have a textArea, and i can’t let the user type ‘%’ on it; to handle this problem i did the following:

html:

<div class="col-12 col-xs-12 col-sm-12 col-md-6">
            <div class="col-md-12 label-base">

                <label for="exampleFormControlTextarea1">Justificativa</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>
        </div>

The function inside my controller:

 $scope.test = function () {
        var txtarea = document.getElementById("exampleFormControlTextarea1");
        txtarea.addEventListener("input", function() {
            txtarea.value = txtarea.value.replaceAll("%", "");
        })
    }

I’m pretty sure the logic inside the function works, but somehow the onkeypress attribute is not calling my function… I can still type ‘%’ in the text area.

Any suggestion??
Don’t know what i’m doing wrong.

Source: AngularJS Questions

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.