You are here

function library_autocomplete_input in Library 7

Same name and namespace in other branches
  1. 5.2 library.module \library_autocomplete_input()
  2. 6.2 library.module \library_autocomplete_input()
  3. 6 library.module \library_autocomplete_input()

Defines the input field for an autocomplete field.

The display is dependent on whether barcodes are enabled.

Parameters

object|null $item: If present, the default value to populate the input field with.

Return value

mixed The form elements of the autocomplete field.

1 call to library_autocomplete_input()
library_transaction_form in ./library.pages.inc
The library transaction form.

File

./library.module, line 1250

Code

function library_autocomplete_input($item = NULL) {
  if (variable_get('library_item_barcodes', LIBRARY_NO_BARCODES) == LIBRARY_BARCODES) {
    $form['item_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Item Barcode'),
      '#default_value' => $item ? $item->barcode : '',
      '#required' => TRUE,
      '#description' => t('Enter the barcode of the item.'),
    );
  }
  else {
    $my_default_value = $item ? $item->title : '';
    $my_default_value .= $item ? ' [id:' . $item->id . ']' : '';
    $form['item_id'] = array(
      '#type' => 'textfield',
      '#title' => t('Library Item'),
      '#default_value' => $my_default_value,
      '#autocomplete_path' => 'library-items/autocomplete',
      '#required' => TRUE,
      '#description' => t('Begin typing the title of the item, then select the chosen item from the provided list.'),
    );
  }
  return $form;
}