I have created a custom module for use with CCK. I have a field called Author, which is wrapped in a fieldset. I want to have a next button that closes the current fieldset, and opens the next, like the way Ubercart does during checkout. But how do I go about doing that? I had thought about doing a hook_form_alter, but I am not sure what I would need to set to accomplish this. They are already set up to be collapsed by default. Can anyone tell me how I might accomplish this?

Comments

epicflux’s picture

This isn't perfect but I'm using this little snippet of code on a webform; adapting it to work on a node form shouldn't be too much of a task.

<?php
//the ids of the feildsets are numbered sequentially: webform-component-project-1, webform-component-project-2, in a webform the id of the fieldset comes from the 'field key' setting
drupal_add_js("
$(function() {
  $('.webform-next-button').click(function() {
    var project = parseInt($(this).attr('rel')); //get current fieldset number
    var nextproject = project + 1; //get the next fieldset number
    var fieldset = $('#webform-component-project-' + project); //load the current fieldset by id
    var nextfieldset = $('#webform-component-project-' + nextproject); //load the next fieldset by id
    if (!fieldset.animating) {
      fieldset.animating = true;
      Drupal.toggleFieldset(fieldset);
    }
    if (!nextfieldset.animating && nextfieldset.hasClass('collapsed')) {
      nextfieldset.animating = true;
      Drupal.toggleFieldset(nextfieldset);
    }
    return false;
  });
});
", 'inline');

?>

Add this link inside the fieldset you want a next button in, the rel tag should match the number in the id of the current fieldset: (this part could be done with jquery)

<a rel="1" class="webform-next-button" href="#">next</a>

Have a look at the file collapse.js that ships with drupal to see how that feature works.

WillHall’s picture

Yeah, that should get you going - if you link us to the page we can provide a more precise version.