Reputation: 792
Im using the textangular, and I need to limit the length of the text. I know that this can be sone using ta-max-text.
But I need to display a error if the text excedes the limit. Textangular sets the model to undefined, when the limit is excedded. This leaves me with a problem. When the page is loaded initialy, the model is also undifined.
How can I figure out if the model is undefined due to a fresh page load or because the limit have been excedded?
Can I access the hidden text in any way?
https://github.com/fraywing/textAngular
Upvotes: 2
Views: 2728
Reputation: 2337
Just checked ta-max-text directive source. It sets the validation false your textarea like this :
ctrl.$setValidity('taMaxText', false);
You can use ng-if directive and check for validity property of your textArea to hide or show message.
ng-if="yourFormName.$error.taMaxText"
Here is the demo link. You can show alert span if your text length > 10.
Upvotes: 4
Reputation: 16498
Please see here http://plnkr.co/edit/MegBJYkkyh3qsNJhyfNP?p=preview
<div ng-model="content" text-angular="" ></div>
<h3 ng-show="content.length > 20">Text tooo long</h3>
Upvotes: 2