When creating nodes in Drupal that have one or more date fields, it can be handy if the values for the 'To' date fields (date & time) are automatically changed to the values that were filled in the 'From' date fields. For example, when events take place on the same day, this can ease data input and make life easier for authors.
The following code does this by using a bit of jQuery. This code is pretty generic, for use with date.module (http://drupal.org/project/date, v6.x-2.4, the stable release at the time of writing).
It should be pretty straight forward to adapt this for use in your own project. The only thing that needs to be changed is the < field_name > in the first selector's ID: you should replace this with your date field's name, since date.module doesn't provide us with a more generic ID.
Drupal.behaviors.DateChange = function (context) { $('#<field_name>_values tr fieldset').each(function() { var fieldset = $(this); var fromDateField = fieldset.children('div').eq(0).children('div').eq(0).children('div').eq(0).children('input.form-text'); var toDateField = fieldset.children('div').eq(1).children('div').eq(0).children('div').eq(0).children('input.form-text'); toDateField.focus(function() { var fromDateVal = fromDateField.val(); if (fromDateVal) { toDateField.val(fromDateVal); } }); var fromTimeField = fieldset.children('div').eq(0).children('div').eq(0).children('div').eq(1).find('input.form-text'); var toTimeField = fieldset.children('div').eq(1).children('div').eq(0).children('div').eq(1).find('input.form-text'); toTimeField.focus(function() { var fromTimeVal = fromTimeField.val(); if (fromTimeVal) { toTimeField.val(fromTimeVal); } }); }); };






Thanks for the share Bruno!
Thanks for the share Bruno!
Thanks of course for the tip.
Thanks of course for the tip. I'm commenting principally to say how good your site looks. I can't think of too many drupal blog-portfolios as well-designed as this. Great work!
Thanks Nigel
Thanks, we are proud of it too :-)
Post new comment