Hello,
I’m working on a feature to update follower counters in real-time (without page refresh)
when a user clicks the follow/unfollow button.
Currently, I have a working solution for simple numbers (0-999), but I’d like to know the best approach to handle abbreviated numbers (1K, 1.5M, etc.) when using the @post(followers.accepted).abbreviate() dynamic tag.
Current implementation:
I’m using this JavaScript code that intercepts the follow action and updates the counter displayed in the Advanced List widget (Action button):
https://pastebin.com/twa2HeDP
It works perfectly for simple numbers (0, 5, 123, etc.).
My questions:
1. Does the AJAX response from `user.follow_post` include the updated follower count? If yes, what’s the response structure? (I only see `{success: true}` currently)
2. If not, would you recommend:
– Replicating the `\Voxel\abbreviate_number()` PHP logic in JavaScript?
– Making an additional AJAX call to fetch the updated count?
– Another approach?
3. Does Voxel trigger any JavaScript custom events after a successful follow action that I could hook into?
Context:
– The counter is displayed using: `@post(followers.accepted).abbreviate()`
– HTML structure: The number is a textNode inside `.ts-initial` and `.ts-reveal` spans
– Currently works fine for numbers < 1000, but would fail with "1.2K" format
Thanks for your help!
©2025 Created with 27collective LLC. All rights reserved