-
Notifications
You must be signed in to change notification settings - Fork 3.4k
md-maxlength character count doesn't update when changed in controller #1983
Comments
This is an actual issue. Has been also mentioned in #1903. |
The key line of code seems to be right here: https://github.com/angular/material/blob/master/src/components/input/input.js#L323 Instead of using element.val() to get the latest value of the input field, why not use ngModelCtrl? Is it okay to reference ngModelCtrl.$modelValue in this context? If that seems like a valid change, I'd like to try my hand at a PR fixing it with a corresponding test. |
I created this example in codepen.io (http://tinyurl.com/ngfhxcu) where I "override" the md-maxlength directive and have added the proposed change by @breeze4 for better reference. Please consider include this change and make the respective test framework |
@batressc nice codepen but the problem with this is once you go over the md-maxlength (when I just tried doing that it says you are persistently at 0/150 or whatever rather than 159/150) so it gives incorrect information the length measurement became off. |
Indeed, using the |
Since it has been moved to the backlog, does it mean it won't be fixed anytime soon? |
+1. |
+1 |
2 similar comments
+1 |
+1 |
In your clearForm function:
Worked for me. |
+1 |
+1 |
Hello @ThomasBurleson. A resolution on closing this item will be much appreciated. This and most other items that were closed are missing resolution. |
This issue is closed as part of our deprecation effort.
|
Referencing #8351 |
I managed to find a workaround based on what @ogaihtorecic said (which didn't work for me), using Angular 1.3.20 and Angular-Material 1.0.5:
|
I wrote a simple code that could solve this problem in your view: in your controller: var fakeMaxLen; // call this function after your data model was changed and you need to update char counter // you can disable animation of .md-errors-spacer class and set visibility to hidden, when process started |
codepen - (http://tinyurl.com/ngfhxcu) given by @batressc is working fine for the issue but it has one issue mentioned by @zargold . By just modifying the codepen with one condition It is working fine for me. Try this codepen with below renderCharCount function.
|
+1 |
If an input field has a md-maxlength showing the character count of the field, (ex. 34/40). And the form is submitted, and I clear the field in the controller (vm.task.field = ''). The counter will remain at 34/40 with no text in the field.
Related to #1870
The text was updated successfully, but these errors were encountered: