diff --git a/modules/book/book.admin.inc b/modules/book/book.admin.inc index 84cbe13..ae4f779 100644 --- a/modules/book/book.admin.inc +++ b/modules/book/book.admin.inc @@ -182,9 +182,13 @@ function _book_admin_table_tree($tree, &$form) { '#size' => 40, ), 'weight' => array( - '#type' => 'weight', + // Using a textfield and a validator instead of a simple weight select + // to avoid unnecessarily oversized HTML for books with hundreds of + // pages. + '#type' => 'textfield', + '#element_validate' => array('_book_validate_integer'), '#default_value' => $data['link']['weight'], - '#delta' => 15, + '#title' => t('Weight for @title', array('@title' => $data['link']['title'])), ), 'plid' => array( '#type' => 'textfield', diff --git a/modules/book/book.module b/modules/book/book.module index 56f839a..7a3c062 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -382,10 +382,12 @@ function _book_add_form_elements(&$form, $node) { $form['book']['plid'] = _book_parent_select($node->book); $form['book']['weight'] = array( - '#type' => 'weight', + // Using a textfield and a validator instead of a simple weight select to + // avoid unnecessarily oversized HTML for books with hundreds of pages. + '#type' => 'textfield', + '#element_validate' => array('_book_validate_integer'), '#title' => t('Weight'), '#default_value' => $node->book['weight'], - '#delta' => 15, '#weight' => 5, '#description' => t('Pages at a given level are ordered first by weight and then by title.'), ); @@ -1093,3 +1095,11 @@ function book_menu_subtree_data($item) { return $tree[$cid]; } +// Helper function borrowed from upstream. +// http://api.drupal.org/api/drupal/includes--form.inc/function/element_validate_integer/7 +function _book_validate_integer($element, &$form_state) { + $value = $element['#value']; + if ($value !== '' && (!is_numeric($value) || intval($value) != $value)) { + form_error($element, t('%name must be an integer.', array('%name' => $element['#title']))); + } +}