Enabling and disabling button

27 views
Skip to first unread message

José

unread,
Mar 21, 2012, 2:37:19 PM3/21/12
to CoffeeKup
I have a form in coffeekup (using express, etc.) with some fields and
two buttons (update and close). I would like to enable the update
button only if a change occurred in the fields, otherwise I should
keep it disabled. I tried to use jQuery, but I am not really getting
around doing. Does any have any idea how to go about this?
thanks in advance
José

David Noelte

unread,
Mar 21, 2012, 4:35:26 PM3/21/12
to coff...@googlegroups.com
this doesnt have anything directly to do with coffekup 
what you looking for is javascript ie jquery that watches an element for changes and then enables the html element button which is the update button so you can click it.

you can accomplish this with jquery.change()


this should get you further

Jose G. Quenum

unread,
Mar 22, 2012, 8:58:48 AM3/22/12
to coff...@googlegroups.com
David,
thanks for your response. Actually, I took a look at jquery as an alternative to get this done. I just don't know how to properly connect it to CoffeeKup.
For example, in my view I added the following script:

coffeescript ->
$('#title').on 'change', () ->
if $('#title').val().length is 0
$('#btn_update').attr('disabled', true)
else
$('#btn_update').attr('disabled', false)

with title being the id of an input for the title and btn_update the id of the update button. However, nothing happens when the values change. I am sure I am missing something to properly hook the script up with the button and trigger the right behavior. Can someone plz point it out?
thanks in advance

Hypee

unread,
Mar 23, 2012, 4:00:33 AM3/23/12
to coff...@googlegroups.com
Hi, 

The correct syntax is :

$('#title').change ->          
  console.log "change event"

But the event is fired only when the user leaves the input field, that's probably not what you want, so you might look at the .keyup() event instead.

Jose G. Quenum

unread,
Mar 27, 2012, 5:16:15 AM3/27/12
to coff...@googlegroups.com
thanks Hypee for your clarifications. The actual code that worked for me is:

show_title = ->
$('#title').change ->
if $('#title').val().length is 0
if all_boxes_empty()
$('#btn_update').attr('disabled', true)
else
$('#btn_update').attr('disabled', false)

$(show_title)
Reply all
Reply to author
Forward
0 new messages