-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Character count message does not update when textarea is updated programmatically #1677
Comments
This issue is related so changing how we detect changes could fix two issues: #1028 It's also worth noting that custom elements (web components) cover these sorts of cases. |
Also related: #1530 |
I spiked the idea of using Object.defineProperty to watch value and it seems to work but I don't know how much of a good idea it is, feels risky. I've also found out that MutationObservers only can detect changes in attributes not properties so may not work for values. I've created to show that only attribute changes can be observed: https://jsbin.com/qajudohulo/edit?js,console,output Custom elements allow property to be observed: https://jsbin.com/yeduzof/2/edit?html,js,console,output Patching the dom element with Object.defineProperty (IE9+): |
@NickColley to look into other approaches for another hour. |
I think this may have been fixed by #1868 I've adapted Nick's old Glitch with similar code but now pulling in GOVUK Frontend 3.8.0. The problem seems to be resolved once that new version is being used. I think this also means that this related issue with checkboxes is fixed too. Glitch here: https://lyrical-hilarious-fir.glitch.me/ @36degrees @hannalaakso what do you think - are you happy for me to close these issues? |
I think it's only looks like it's fixed because the example now updates the textarea value after the If you change the value after the |
This was raised by a user:
I have reproduced this with the following code:
You can see a live example here: https://govuk-frontend-issue-1677.glitch.me
The count message is only updated when the component is focused:
govuk-frontend/src/govuk/components/character-count/character-count.js
Lines 96 to 97 in cfca85f
So right now you need to either run
characterCountInstance.checkIfValueChanged();
manually after you've updated the value programmatically for it to be checked.The text was updated successfully, but these errors were encountered: