Course Database

Events happening in the community are now at Drupal community events on www.drupal.org.
Posted by saepl on May 19, 2010 at 6:07pm

I am creating a database where users can enter a course, the times it's offered, etc. I can do this using CCK and a custom node type, but I have a problem saying, for example that if the delivery type is distance than a class room and class time is not required.

Categories: ,

Comments

Use jquery

Posted by mdryan on May 20, 2010 at 9:48am

The way I've solved this in the past is to include a short bit of custom jquery which hides or shows part of the form on the onchange event of the select element. Something along the lines of the following (untested) for your example:

Drupal.behaviors.course_entry = function(context) {
$('#delivery-type-form-element-id').change(function(event) {
var new_option = $(this).children('option:selected').text();
if (new_option=='distance') {
$('#classroom-form-element-wrapper-id').hide();
$('#start-time-form-element-wrapper-id').hide();
}
else {
$('#classroom-form-element-wrapper-id').show();
$('#start-time-form-element-wrapper-id').show();
}
});
}

Obviously this doesn't stop someone unhiding these elements and submitting values if they wanted to be malicious, so if this were important then you'd have to be careful to disregard the values on submission but that doesn't sound like it would be a problem in this case.

-Matt

Drupal in Education

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

AltStyle によって変換されたページ (->オリジナル) /