I want to limit the maximum length of the text so that it does not exceed the length of the column in the database. I put this restriction on the backend, and now I want to use it in the interface.
I am using TinyMCE v4.3.3 with the angular -ui-tinymce v0.0.12 plugin and AngularJS v1.4.6.
JS:
var tinymceOpts = { toolbar: false, menubar: false, // do not add <p></p> from the start: forced_root_block: '' }
HTML:
<textarea ui-tinymce="tinymceOpts" ng-model="body" name="body" ng-maxlength="100" required> {{ body }} </textarea> <span ng-show="form.body.$error.maxlength" class="error"> Reached limit! </span>
As you can see, I use the ng-maxlength
attribute to limit the length of <textarea>
.
Expected result: the input is confirmed, and the error message is displayed only if the length of the content (with the included tags) has exceeded the limit (in this case, 100 characters).
Actual result:
The input state of the form is set to invalid when the input contains some text (regardless of length).
The number of characters (in the lower right corner) is calculated for testing:
this.getCharCount = function() { var tx = editor.getContent({format: 'raw'}); return tx.length; };
source share