0

I am trying to use the autocomplete addon in agile toolkit (I am still very much new to this, but it seems to be very well suited for my needs). Autocomplete Basic works, but when I use Plus and press the plus-button I get an error connected to no model set. In the Plus source the self-model should be used - but I don't understand how I should set the model of the autocomplete form.

This is the important part of the stack trace, I think:

  • Frontend_page_form: Form->setModel(Null)
  • Frontend_createquestions_form_question_id: autocomplete\Form_Field_Plus->autocomplete{closure}(Object(Page))

This is my model:

class Model_QuestionInCollection extends Model_Table {
public $entity_code='questionincollection';
function init(){
    parent::init();
    $this->hasOne('Question')->display(array('form'=>'autocomplete/Plus'));

This is the code:

$form=$this->add('Form');
$form->setModel('QuestionInCollection');

--- EDIT

I ended up changing the model in autocomplete, and now it works, showing that something is wrong in the original "$self->model" - but of course it cannot be generalized. I did some extra changes (to make the new record show up in the autocomplete-field), so Autocomplete/Plus now is like this:

<?php
namespace autocomplete;

class Form_Field_Plus extends Form_Field_Basic
{
  function init()
  {
    parent::init();
    $self = $this;

    $f = $this->other_field;

    // Add buttonset to name field
    $bs = $f->afterField()->add('ButtonSet');

    // Add button - open dialog for adding new element
    $bs->add('Button')
        ->set('+')
        ->add('VirtualPage')
        ->bindEvent('Add New Record', 'click')
            ->set(function($page)use($self) {
        $model=$this->add('Model_Question');
        $form = $page->add('Form');
                $form->setModel($model); //Was: $self->model
                //Would be nice if it worked...: $form->getElement($model->title_field)->set($self->other_field->js()->val());
                if ($form->isSubmitted()) {
                    $form->update();
                    $js = array();
                    $js[] = $self->js()->val($form->model[$model->id_field]);
                    $js[] = $self->other_field->js()->val($form->model[$model->title_field]);
                    $form->js(null, $js)->univ()->closeDialog()->execute();
                }
            });
}

}

jeppeb
  • 103
  • 8
  • Better use $title instead of $entity_code, because $entity_code is deprecated. At the moment that will not change anything, but at some point $entity_code will be dropped completely. – DarkSide Aug 17 '13 at 23:47
  • I'll take a look at this issue in next few days and fix it if needed. By the way, do you use recent version of ATK and Autocomplete addon from Github? If not, then please try that. – DarkSide Aug 18 '13 at 00:01
  • Thanks. Yes I use the addon from Github. It might just be me not understanding how to implement the Plus-version. – jeppeb Aug 20 '13 at 18:18
  • Please post your Question model too. – DarkSide Aug 26 '13 at 16:03

1 Answers1

0

Here is an example on using autocomplete: http://codepad.demo.agiletech.ie/interactive-views/autocomplete

You can manually create a form and link the field with Model.

If that works fine, you can move on to trying and get your own example working. It seems OK, and should work in theory.

romaninsh
  • 10,606
  • 4
  • 50
  • 70
  • Thanks for answering! Autocomplete/Basic works fine. The problem is autocomplete/Plus - I don't know how to make it save new records in the used model (Question) when working with another model (QuestionInCollection). – jeppeb Aug 19 '13 at 15:31