0

I have the following in my view...

checkbox

<input id="event_requires_registration" name="event[requires_registration]" type="checkbox" value="1">

text input

<input id="event_registration_contact_id" name="event[registration_contact_id]" size="30" type="text" value="25241" class="ui-autocomplete-input" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true">

...and this coffeescript:

$ ->
    if $('#event_requires_registration').is ':checked'
        !$('#event_registration_contact_id')[0].disabled
    else
        $('#event_registration_contact_id')[0].disabled
    $('#event_requires_registration').click ->
        $('#event_registration_contact_id').attr 'disabled', !@checked
        return

If I check/uncheck the box when editing the page the text input is disabled/enabled as it should be. However, if the box is unchecked, when I load the page, I can still enter text in the input. If the box is unchecked, I want the input disabled when the page loads.

Mark Locklear
  • 4,253
  • 1
  • 39
  • 67
  • 2
    Probably unrelated, but what is `!$('#event_registration_contact_id')[0].disabled` supposed to do? Also, to call a no-arg function in CS you must use the `()` otherwise it's just a function reference. – Dave Newton Jun 10 '15 at 15:52
  • Thanks all for the help. This is what ended up working for me: ```$ -> if $('#event_requires_registration').attr 'checked' $('#event_registration_contact_id').prop('disabled', false) else $('#event_registration_contact_id').prop('disabled', true) $('#event_requires_registration').click -> $('#event_registration_contact_id').attr 'disabled', !@checked return``` – Mark Locklear Jun 10 '15 at 18:09

0 Answers0