Closed emagnier closed 10 years ago
I like the idea of extending these events, but keydown
and keypress
will always proxiying event to keyup
, which will makes the callback inconsistent. Thought?
Yeah I see.. I'll re-take a look on it this weekend to see if I can make something better or not.
Hi! Any updates on this? I would like to add a word count to my bootstrap-markdown
textareas and can't find a way to do it :(
I think this will be possible if PR #61 is merged,the onchange event that is added triggers when a user is typing in the textarea
Please take a look at PR #72, i think this pull request has the changes from this PR already included
I finally solved this with CoffeeScript code (sorry for not posting before, totally forgot it!). In my case, the user couldn't write more than max
words (say 140).
updateCounter = (textarea, counter, max, button) ->
words = textarea.val().trim().split(/\s/)
empty_lines = words.filter (x) -> x == ""
cnt = words.length
cnt = cnt - empty_lines.length
counter = $(counter)
counter.text (max - cnt) + " Words left"
if cnt > max
counter.attr "class", "over-limit"
button.toggleClass('inactive')
else
counter.attr "class", "on-limit"
button.toggleClass('inactive')
window.wordCount = (textarea, counter, max, button) ->
textarea = $(textarea)
submit_button = $(button)
textarea.on 'keyup blur', ->
updateCounter(textarea, counter, max, submit_button)
updateCounter(textarea, counter, max, submit_button)
counter
is a span
tag that shows the words you can still write.
Thanks!
@acrobat: Thanks for your following up. I had rebased my branch, but indeed #72 seems to include my changes. So I'm closing my PR for now.
This helps to debug certain additional buttons and to add features like word count.