Enable / Disable Radio Button Form Field using chain.js

15 views
Skip to first unread message

ska

unread,
Mar 4, 2009, 12:26:48 PM3/4/09
to chainjs
Hello all,

Firstly to say that chain.js is absolutely great. I learned about it a
few days ago and have already put it to use in about four different
scenarios.

Anyway, my question involves using chain() to disable a radio button.
My script gathers json data from a script using AJAX and then a radio
button needs to be either enabled or disabled according to the
evaluation of data.fully_booked.

I have something like the below in my code. Is there a way of setting
the radio button to disabled? I'm just not quite sure how to control
this from within chain().

$('#date_row_items')
.items('destroy') /* clear previous items */
.items(data) /* parse items */
.chain({
'.start_date_gp': {
value: '{start_date}',
title: ''{did}|{duration}|{times}|{cost}',
disabled: function(data, el) { // how to disable
radio button?
if(!data.fully_booked) {
// something
} else {
// something
}
return // something
}
}
});


<div id="date_row_items">
<div class="item">
<span class="start_date">&nbsp;</span>
<input type="radio" class="start_date_gp" name="start_date_gp"
id="start_date_gp" value="" onclick="doDateSelect(this);" />
<span class="fully_booked">&nbsp;</span>
</div>
</div>

Any pointers very much appreciated. Thanks.

raid_ox

unread,
Mar 4, 2009, 2:58:52 PM3/4/09
to chainjs
Hi,

did you try:

disabled: function(data, el) {
if(data.fully_booked) {
return 'disabled';
} else {
return '';
}
}

rizqi

ska

unread,
Mar 4, 2009, 6:03:17 PM3/4/09
to chainjs
Thanks for the reply rizqi. Indeed I did try that and it didn't work.
However, I've just revisited my code and looks like I've got a slight
syntax error! So yes, it looks like this is correct after all. Many
thanks!
Reply all
Reply to author
Forward
0 new messages