function render($mode = false)
    {
        $config = $this->field->getConfiguration();
        $value = false;
        if ($this->value instanceof DynamicListItem) {
            // Loaded from database
            $value = $this->value->get('id');
            $name = $this->value->get('value');
        } elseif ($this->value) {
            // Loaded from POST
            $value = $this->value;
            $name = $this->getEnteredValue();
        }
        if (!$config['typeahead'] || $mode == 'search') {
            $this->value = $value;
            return parent::render($mode);
        }
        $source = array();
        foreach ($this->field->getList()->getItems() as $i) {
            $source[] = array('value' => $i->get('value'), 'id' => $i->get('id'), 'info' => $i->get('value') . " -- " . $i->get('extra'));
        }
        ?>
        <span style="display:inline-block">
        <input type="text" size="30" name="<?php 
        echo $this->name;
        ?>
"
            id="<?php 
        echo $this->name;
        ?>
" value="<?php 
        echo $name;
        ?>
"
            placeholder="<?php 
        echo $config['prompt'];
        ?>
" autocomplete="off" />
        <input type="hidden" name="<?php 
        echo $this->name;
        ?>
_id" id="<?php 
        echo $this->name;
        ?>
_id" value="<?php 
        echo $value;
        ?>
"/>
        <script type="text/javascript">
        $(function() {
            $('input#<?php 
        echo $this->name;
        ?>
').typeahead({
                source: <?php 
        echo JsonDataEncoder::encode($source);
        ?>
,
                property: 'info',
                onselect: function(item) {
                    $('input#<?php 
        echo $this->name;
        ?>
').val(item['value'])
                    $('input#<?php 
        echo $this->name;
        ?>
_id').val(item['id'])
                }
            });
        });
        </script>
        </span>
        <?php 
    }
    function render($how)
    {
        if ($how == 'search') {
            return parent::render($how);
        }
        $name = $this->getEnteredValue();
        $config = $this->field->getConfiguration();
        if (is_array($this->value)) {
            $name = $name ?: current($this->value);
            $value = key($this->value);
        } else {
            // Pull configured default (if configured)
            $def_key = $this->field->get('default');
            if (!$def_key && $config['default']) {
                $def_key = $config['default'];
            }
            if (is_array($def_key)) {
                $name = current($def_key);
            }
        }
        $source = array();
        foreach ($this->field->getList()->getItems() as $i) {
            $source[] = array('value' => $i->getValue(), 'id' => $i->getId(), 'info' => sprintf('%s %s', $i->getValue(), ($extra = $i->getAbbrev()) ? "-- {$extra}" : ''));
        }
        ?>
        <span style="display:inline-block">
        <input type="text" size="30" name="<?php 
        echo $this->name;
        ?>
_name"
            id="<?php 
        echo $this->name;
        ?>
" value="<?php 
        echo Format::htmlchars($name);
        ?>
"
            placeholder="<?php 
        echo $config['prompt'];
        ?>
" autocomplete="off" />
        <input type="hidden" name="<?php 
        echo $this->name;
        ?>
[<?php 
        echo $value;
        ?>
]" id="<?php 
        echo $this->name;
        ?>
_id" value="<?php 
        echo Format::htmlchars($name);
        ?>
"/>
        <script type="text/javascript">
        $(function() {
            $('input#<?php 
        echo $this->name;
        ?>
').typeahead({
                source: <?php 
        echo JsonDataEncoder::encode($source);
        ?>
,
                property: 'info',
                onselect: function(item) {
                    $('input#<?php 
        echo $this->name;
        ?>
_name').val(item['value'])
                    $('input#<?php 
        echo $this->name;
        ?>
_id')
                      .attr('name', '<?php 
        echo $this->name;
        ?>
[' + item['id'] + ']')
                      .val(item['value']);
                }
            });
        });
        </script>
        </span>
        <?php 
    }