Thank you. I have an other approach to this. I will make a plugin based on that.
rrd 2014-10-02 7:44 GMT+02:00 heavyKevy <[email protected]>: > I got the Autocomplete widget to work with the following: > > Same autocomplete widget file as you but different code in controller and > view file: > Controller: > public $helpers = [ > 'Form' => [ > 'widgets' => [ > 'autocomplete' => ['App\View\Widget\Autocomplete'] > ] > ] > ]; > > add.ctp: > <?php > echo $this->Html->css('jquery-ui.theme.css'); > echo $this->Html->script('jquery',['block'=>true]); > echo $this->Html->script('jquery-ui',['block'=>true]); > $this->Html->scriptStart(['block'=>true,'safe'=>false]); > ?> > <!-- > $(document).ready(function(){ > > var availableTags =[ <?php > $prefix = ''; > $lst =''; > foreach ($salesPeople as $sp) > { > $lst .= $prefix . '"' . $sp . '"'; > $prefix = ', '; > } > echo $lst; > ?>]; > <?php > if(strlen($purchase->sales_person)>0){?> > $( "#sales_person" ).autocomplete({source: > availableTags}).val('<?= > $purchase->sales_person?>').data('autocomplete')._trigger('select'); > <?php > }?> > }); > > //--> > > <?php > $this->Html->scriptEnd(); > // Using a classname. > $this->Form->addWidget( > 'autocomplete', > ['App\View\Widget\Autocomplete'] > ); > ?> > <div class="purchases form"> > <?= $this->Form->create($purchase,['templates'=>['autocomplete' => '<input > id="sales_person" name="{{name}}"{{attrs}}>'], > > 'onsubmit'=>'return validateForm()']); ?> > <fieldset> > <legend><?= __('Add Purchase'); ?></legend> > <?php > echo $this->Form->input('sales_person', ['type' => > 'autocomplete','label'=>'Sales > Person','id'=>'sales_person','required'=>true]); > </fieldset> > <?= $this->Form->button(__('Submit')); ?> > <?= $this->Form->end(); ?> > </div> > > > I eliminated all of the items not necessary for the example, so there are > likely errors in there, but it should give you the gist of what is needed > for the autocomplete to work. > > Regards, > --Kevin > > On Tuesday, September 30, 2014 7:33:24 PM UTC+7, Radharadhya Dasa wrote: >> >> Hi, >> >> I am trying to make an autocomplete input work on Cake 3.0 >> >> The current 3.0 cookbook gives a code example here : >> http://book.cakephp.org/3.0/en/core-libraries/helpers/form.html >> >> If I try it I get an error message: >> *Fatal error*: Declaration of App\View\Widget\Autocomplete::render() >> must be compatible with Cake\View\Widget\WidgetInterface::render(array >> $data, Cake\View\Form\ContextInterface $context) in >> */home/rrd/public_html/sanga/src/View/Widget/Autocomplete.php* on line >> >> *6*If I change my render function to >> >> *public function render(array $data, Cake\View\Form\ContextInterface >> $context) {* >> Still I get the same error message. >> >> Any idea how to solve this? >> >> rrd >> > -- > Like Us on FaceBook https://www.facebook.com/CakePHP > Find us on Twitter http://twitter.com/CakePHP > > --- > You received this message because you are subscribed to the Google Groups > "CakePHP" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/cake-php. > For more options, visit https://groups.google.com/d/optout. > -- Like Us on FaceBook https://www.facebook.com/CakePHP Find us on Twitter http://twitter.com/CakePHP --- You received this message because you are subscribed to the Google Groups "CakePHP" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php. For more options, visit https://groups.google.com/d/optout.
