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.