Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag module #16

Open
taiwen opened this issue Feb 25, 2013 · 2 comments
Open

Tag module #16

taiwen opened this issue Feb 25, 2013 · 2 comments
Labels
Milestone

Comments

@taiwen
Copy link
Owner

taiwen commented Feb 25, 2013

See https://github.com/taiwen/pi/wiki/Pi-Tag-Module

@voltan
Copy link
Collaborator

voltan commented Feb 27, 2013

Example codes for Typeahead

PHP

    public function ajaxAction()
    {
        if ($this->request->isPost()) {
            $params = $this->request->getPost();
            if (isset($params['key']) && !empty($params['key'])) {
                // Get info
                $order = array('count DESC', 'id DESC');
                $columns = array('id', 'term');
                $where = array('term LIKE ?' => '%' . $params['key'] . '%');
                // Set select
                $select = Pi::model('tag', 'tag')->select()->columns($columns)->where($where)->order($order)->limit(10);
                $rowset = Pi::model('tag', 'tag')->selectWith($select);
                foreach ($rowset as $row) {
                    $message[$row->id] = $row->toArray();
                    $result[] = $message[$row->id]['term'];
                }
                // return result
                echo Json::encode($result);
            }
        }
    }

JS in template

    $this->jQuery();
    $this->bootstrap('js/bootstrap.js');

    // For check tag
    $('.tagbar').typeahead({
         minLength: 1,
         source: function (query, process) {
            return $.post("<?php $this->url(...); ?>" , { key: query }, function (data) {
               var result = JSON.parse(data);
                process(result);
            });
         }
    });

Form

            $this->add(array(
                'name' => 'tag',
                'options' => array(
                    'label' => __('Tags'),
                ),
                'attributes' => array(
                    'type' => 'text',
                    'id' => 'tagbar',
                    'description' => '',
                    'autocomplete' => 'off',
                     'data-provide' => 'typeahead',
                     'data-items' => '10',
                     'data-source' => '',
                     'class' => 'tagbar',
                )
            ));

@voltan
Copy link
Collaborator

voltan commented Feb 27, 2013

And its good example too : http://welldonethings.com/tags/manager

taiwen pushed a commit that referenced this issue May 21, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants