Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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;
}
}
?>
Comment | File | Size | Author |
---|---|---|---|
#3 | 1013224-misalign-col.png | 5.35 KB | iStryker |
#1 | cck-table-validate-number-of-columns-patch-1.txt | 2.01 KB | joetsuihk |
cck-table-validate-number-of-columns-patch-0.txt | 2.29 KB | joetsuihk |
Comments
Comment #1
joetsuihk CreditAttribution: joetsuihk commentedissue messing up in previous patch file, this one fixed.
Comment #2
iStryker CreditAttribution: iStryker commentedDo you think that this is something that should be enforce, or be optional?
Comment #3
iStryker CreditAttribution: iStryker commentedI have added an optional checkbox to the field form. By default it is enabled.
http://drupal.org/files/1013224-misalign-col_0.png">
Comment #4
iStryker CreditAttribution: iStryker commentedCommited to D6 & D7 branch