Index: pollfield.module --- pollfield.module Base (BASE) +++ pollfield.module Locally Modified (Based On LOCAL) @@ -147,11 +147,10 @@ '#type' => 'fieldset', '#title' => pollfield_fieldset_title($element), '#collapsible' => isset($element['#collapsible']) ? $element['#collapsible'] : TRUE, - '#collapsed' => isset($element['#collapsed']) ? $element['#collapsed'] : TRUE, + '#collapsed' => isset($element['#collapsed']) ? $element['#collapsed'] : strlen($element['question']['#value']) == 0, '#attributes' => $element['#attributes'], '#children' => $element['#children'], ); - return theme('fieldset', $fieldset); } @@ -1048,8 +1047,10 @@ // Number of default choices defines for this pollfield $node_choices = unserialize($element['#value']['choice']); $default_choices = unserialize($default_value['choice']); - $count_choices = max($count_default_response_fields, intval(count($node_choices))); + // Use $element['#value']['group'] when building form after add_choice action performed + $count_choices = max($count_default_response_fields, intval(count($node_choices ? $node_choices : $element['#value']['group']))); + // Build as many choice form elements as are called for, // either by the default number of responses, default choice entires, // or chocies already defined in the node. @@ -1066,14 +1067,7 @@ $value_vote = $default_value['group'][$delta]['votes']; } - // Check to see if the first choice value is empty or not - // before adding more choices. - $first_empty = FALSE; - if ($delta == 0 && drupal_strlen($value_choice) < 1) { - $first_empty = TRUE; - } - - if (drupal_strlen($value_choice) > 0 || $delta << $count_choices || $first_empty) { + if (drupal_strlen($value_choice) > 0 || $delta < $count_default_response_fields) { $element['group'][$delta] = array( '#type' => 'fieldset', '#title' => t('Choice #%delta', array('%delta' => intval($i + 1))), @@ -1101,20 +1095,20 @@ // Check if this is a "More choices" button submit if (strcmp($form_state['clicked_button']['#name'], $nid ."-". $path) == 0) { - if (drupal_strlen($element['group'][$number-1]['choice']['#default_value'])>0) { - $element['group'][$number] = array( + if (drupal_strlen($element['group'][$i-1]['choice']['#default_value']) > 0) { + $element['group'][$i] = array( '#type' => 'fieldset', - '#title' => t('Choice #%delta', array('%delta' => intval($number + 1))), + '#title' => t('Choice #%delta', array('%delta' => intval($i + 1))), '#tree' => TRUE, ); - $element['group'][$number]['choice'] = array( + $element['group'][$i]['choice'] = array( '#title' => t('Response'), '#type' => 'textfield', '#default_value' => '', '#rows' => 2, '#weight' => floatval($pollfield_form['widget']['weight'] + ($delta / 10)), ); - $element['group'][$number]['votes'] = array( + $element['group'][$i]['votes'] = array( '#title' => t('Starting votes count (optional)'), '#access' => $admin_pollfield, '#type' => 'textfield', @@ -1123,7 +1117,7 @@ '#size' => 10, '#weight' => floatval($pollfield_form['widget']['weight'] + ($delta / 10) + .1), ); - $number++; + $i++; } }