To create empty cell, you may use syntax like "1|2|3||4"

add to cck_table.module:

<?php
/**
 * Implementation of hook_field().
 */
function cck_table_field($op, &$node, $field, &$items, $teaser, $page) {
  switch ($op) {
    case 'validate':
      $allowed_values = content_allowed_values($field);
      if (is_array($items)) {
        foreach ($items as $delta => $item) {
          $error_element = isset($item['_error_element']) ? $item['_error_element'] : '';
          if (is_array($item) && isset($item['_error_element'])) unset($item['_error_element']);
          if ($item['value'] != '') {
            $lines = explode("\n", $item['value']);
            $lines = array_map('trim', $lines);
            $lines = array_filter($lines, 'strlen');

            $cell_count;
            foreach ($lines as $line) {
              if(!$cell_count) {
                $cell_count = count(explode('|', $line));
              } elseif($cell_count != count(explode('|', $line))) {
                form_set_error($error_element, t('%name: mis-align number of columns.', array('%name' => t($field['widget']['label']))));
                break;
              }
            }
          }
        }
      }
      return $items;
  }
}
?>
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joetsuihk’s picture

issue messing up in previous patch file, this one fixed.

iStryker’s picture

Do you think that this is something that should be enforce, or be optional?

iStryker’s picture

FileSize
5.35 KB

I have added an optional checkbox to the field form. By default it is enabled.
Only local images are allowed. http://drupal.org/files/1013224-misalign-col_0.png">

iStryker’s picture

Status: Needs review » Closed (fixed)

Commited to D6 & D7 branch