Reputation: 15
I'm trying to enable a button only when my input is filled with at least 18 characters. Here is the HTML code:
<form id="frm.frmEntidade" name="frm.frmEntidade">
<div>
<input type="text" ng-model="entidade.cnpj" id="cnpjEntidade" name="cnpjEntidade" required />
<span class="input-group-btn">
<button title="Buscar Entidade" class="btn btn-primary"
type="button" ng-click="buscarEntidade(entidade.cnpj)" ng-
disabled="frm.frmEntidade.cnpjEntidade.lenght !== 18">
<span class="glyphicon glyphicon-search"></span>
</button>
</div>
</form>
but the button stay awas disabled, anyone could help?
Upvotes: 1
Views: 1856
Reputation: 17289
It's better use ng-minlength
for form validation. by checking $valid
you can enable or disable button
<form id="frm.frmEntidade" name="frm.frmEntidade">
<input type="text" ng-model="entidade.cnpj" id="cnpjEntidade" name="cnpjEntidade" required ng-minlength="18" />
<span class="input-group-btn">
<button title="Buscar Entidade" class="btn btn-primary"
type="button" ng-click="buscarEntidade(entidade.cnpj)"
ng-disabled="!frm.frmEntidade.$valid">
<span class="glyphicon glyphicon-search"></span>
Button
</button>
</span>
</form>
Upvotes: 0
Reputation: 18279
You have a typo error on the word length
. Change:
<button [...]
ng-disabled="frm.frmEntidade.cnpjEntidade.lenght !== 18">
To:
<button [...]
ng-disabled="frm.frmEntidade.cnpjEntidade.length !== 18">
As a side note, this condition check if it is different from 18, not if "input is filled with at least 18 characters".
Upvotes: 2