Vlastny SuggestionInput – problem s url

Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
duskohu
Člen | 778
+
0
-

Caute viete mi poradit robim si SuggestionInput, podedil som ho od TextInput, pridal som mu do data atributu cestu na callback suggestion a pomocou ajaxu chcem volat tento callback, problem mam v tom ze neviem ako spravne mam tu url formulovat aby smerovala na spracovanie callbacku a ako ju odchytit?


    /** @var string */
    private $renderName;

    /** @var callback returning array */
    protected $suggestCallback;

    public function getControl() {
        $container = \Nette\Utils\Html::el('div')->addAttributes(array('class' => 'suggestion-input'));
        /** @var $control \Nette\Utils\Html */
        $control = parent::getControl();

        if ($this->suggestCallback !== NULL) {
            $form = $this->getForm();
            if (!$form || !$form instanceof Form) {
                throw new InvalidStateException("SuggestionInput supports only Nette\\Application\\UI\\Form.");
            }
            $control->attrs['data-tag-suggest'] = $form->getPresenter()->link($this->renderName, array('word_filter' => '%filter%'));
        }
        $container->add($control);
        $container->add(\Nette\Utils\Html::el('script')->setHtml('SuggestionInput.create("' . $this->htmlId . '");'));
        return $container;
    }

    public function setSuggestCallback($suggest) {
        $this->suggestCallback = callback($suggest);
        return $this;
    }

    public static function register() {
        Form::extensionMethod('addSuggestionInput', callback(__CLASS__, 'addSuggestionInput'));
    }

    public static function addSuggestionInput(Form $form, $name, $label = NULL) {
        $form[$name] = new self($label);
        $form[$name]->renderName = 'suggestionInput' . ucfirst($name);
        return $form[$name];
    }

a vo formulari:

        $form->addSuggestionInput('suggest')
                ->setSuggestCallback(function($filter, $count){
                            return ...
                        });

Editoval duskohu (17. 1. 2013 15:12)