Skip to content
Snippets Groups Projects
class.dynamic_forms.php 33.1 KiB
Newer Older
  • Learn to ignore specific revisions
  • Jared Hancock's avatar
    Jared Hancock committed
                $this->value = $value;
    
                return parent::render($mode);
    
    Jared Hancock's avatar
    Jared Hancock committed
            }
    
            $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'),
                );
    
    Jared Hancock's avatar
    Jared Hancock committed
            ?>
            <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; ?>"/>
    
    Jared Hancock's avatar
    Jared Hancock committed
            <script type="text/javascript">
            $(function() {
    
                $('input#<?php echo $this->name; ?>').typeahead({
    
    Jared Hancock's avatar
    Jared Hancock committed
                    source: <?php echo JsonDataEncoder::encode($source); ?>,
    
                    property: 'info',
    
    Jared Hancock's avatar
    Jared Hancock committed
                    onselect: function(item) {
    
                        $('input#<?php echo $this->name; ?>').val(item['value'])
    
                        $('input#<?php echo $this->name; ?>_id').val(item['id'])
    
    Jared Hancock's avatar
    Jared Hancock committed
                    }
                });
            });
            </script>
            </span>
            <?php
        }
    
    
        function getValue() {
            $data = $this->field->getSource();
            // Search for HTML form name first
            if (isset($data[$this->name.'_id']))
                return (int) $data[$this->name.'_id'];
            return parent::getValue();
        }
    
    
        function getEnteredValue() {
            // Used to verify typeahead fields
            return parent::getValue();
        }