Giter Site home page Giter Site logo

Comments (2)

JustGoscha avatar JustGoscha commented on June 25, 2024

You can adapt the template for your needs in autocomplete.js:

{
...
template: '\
        <div class="autocomplete {{ attrs.class }}" id="{{ attrs.id }}">\
          <input\
            type="text"\
            ng-model="searchParam"\
            placeholder="{{ attrs.placeholder }}"\
            class="{{ attrs.inputclass }}"\
            id="{{ attrs.inputid }}"/>\
          <ul ng-show="completing && suggestions.length>0">\
            <li\
              suggestion\
              ng-repeat="suggestion in suggestions | filter:searchFilter | orderBy:\'toString()\' track by $index"\
              index="{{ $index }}"\
              val="{{ suggestion }}"\
              ng-class="{ active: ($index === selectedIndex) }"\
              ng-click="select(suggestion)"\
              ng-bind-html="suggestion | highlight:searchParam"></li>\
          </ul>\
        </div>'
...
}

In the <li> you can make a sub-tag and style it like you want and access attributes of your suggestion e.g.

<img ng-src="suggestion.imageUrl"><div>{{suggestion.title}}</div>

If the template gets too long you can put it in a separate html file and then import it in autocomplete.js
with.

{
...
templateUrl: 'myTemplate.html',
...
}

It will also look prettier as pure HTML code without the \ on each new line.

from allmighty-autocomplete.

digimantraoffice avatar digimantraoffice commented on June 25, 2024

Hi @JustGoscha ,

Its works , Thanks for your time I have one small doubt

When a user click over any suggestion name must be filled in the input box and there must be some hidden field where I can store ID

For this I update

  • code as

    ng-click="select(suggestion.name,suggestion.id)"

    and in autocomplete.js

      $scope.select = function (suggestion,suggestionid) {
                    if (suggestion) {
                        $scope.selectPageId = suggestionid;
                        console.log(suggestionid);
                        $scope.searchParam = suggestion;
                        $scope.searchFilter = suggestion;
                        if ($scope.onSelect)
                            $scope.onSelect(suggestion);
                    }
                    watching = false;
                    $scope.completing = false;
                    setTimeout(function () {
                        watching = true;
                    }, 1000);
                    $scope.setIndex(-1);
                };
    

    and on the index.html page I add a new field

    <input type="hidden" ng-modal="selectPageId" id="selectPageId" value=""/>
    

    but its not passing the value to that field

    So I update the code like this

      $scope.select = function (suggestion,suggestionid) {
                    if (suggestion) {
                        $('#selectPageId').val( suggestionid );
                        console.log(suggestionid);
                        $scope.searchParam = suggestion;
                        $scope.searchFilter = suggestion;
                        if ($scope.onSelect)
                            $scope.onSelect(suggestion);
                    }
                    watching = false;
                    $scope.completing = false;
                    setTimeout(function () {
                        watching = true;
                    }, 1000);
                    $scope.setIndex(-1);
                };
    

    Which works but i know its a wrong way

  • from allmighty-autocomplete.

    Related Issues (20)

    Recommend Projects

    • React photo React

      A declarative, efficient, and flexible JavaScript library for building user interfaces.

    • Vue.js photo Vue.js

      🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

    • Typescript photo Typescript

      TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

    • TensorFlow photo TensorFlow

      An Open Source Machine Learning Framework for Everyone

    • Django photo Django

      The Web framework for perfectionists with deadlines.

    • D3 photo D3

      Bring data to life with SVG, Canvas and HTML. 📊📈🎉

    Recommend Topics

    • javascript

      JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

    • web

      Some thing interesting about web. New door for the world.

    • server

      A server is a program made to process requests and deliver data to clients.

    • Machine learning

      Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

    • Game

      Some thing interesting about game, make everyone happy.

    Recommend Org

    • Facebook photo Facebook

      We are working to build community through open source technology. NB: members must have two-factor auth.

    • Microsoft photo Microsoft

      Open source projects and samples from Microsoft.

    • Google photo Google

      Google ❤️ Open Source for everyone.

    • D3 photo D3

      Data-Driven Documents codes.