Coder Social home page Coder Social logo

massautocomplete's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

massautocomplete's Issues

Suggest not triggered after SPACE

Hi,

The suggest function is not triggered when the user hit space.

In my app, I would like to implement a feature where I can look up the document I parsed for list of words so that: "development" and "development " give different suggestions.
Is this possible to trigger a new suggestion with ending space?

Thanks.

bower version 0.2.3

Hi. When would the 0.2.3 version be published in bower? I'm stil waiting for my commits in production, don't want to install it from my fork.

Btw, you didn't fix the version in bower.json.

New scope lead to losing two-way binding

Im using mass-autocomplete directive to wrap all my page, as I have autocompleted input everywhere in the page.
Problem is that the directive creates a child scope.
So all the variables that have been initialized by the controller are shaded by a new variable in the child scope. When I modify a variable with an input for example, i only change the child version, not the 'real' one.
The problem doesnt occur when the variable is an object, as only the reference is copied in the child scope.
See example here: http://jsbin.com/tevagiciji/edit?html,js,output

Do I have a wrong usage of mass-autocomplete ? How to overcome this problem ?

Thank you

mass-autocomplete-item only allows strings

In angular, the item should allow arrays, objects, and any notation so long as it points to a valid object on the scope.

http://jsbin.com/dewukirimo/1/

The following throws an error on any notation besides for a string notation.
var options = scope[attrs.massAutocompleteItem];

scope: false,
link: function (scope, element, attrs, required) {
// Prevent html5/browser auto completion.
attrs.$set('autocomplete', 'off');
element.bind('focus', function () {
var options = scope[attrs.massAutocompleteItem];
if (!options) throw "Invalid options";
required[0].attach(required[1], element, options);

Instead, scope isolation should be used to retrieve the property through angular.

Template

How can I change the module's template?

clear input if no match found

Could you give me some idea how to clear the user input if no match with the results.
I want force user to select from the results list.

Thanks in advance.

Victor

Position incorrect when on fixed elements

JSbin with issuee:
http://jsbin.com/xirukapuho/1/edit?html,css,js,output

When the dropdown is on a fixed element, floating somewhere below the top of the page, the dropdown position is calculated incorrectly. I think this is due to the fact that the position is calculated relative to the document, but the absolute style is relative to the parent.

This could solved by finding the directive element's offset from the top of the page (and left) and subtracting from the position value.

Capture the input ng-model when pressing enter

Love the directive btw.

I would like to be able to capture the input ng-model when the user simply enters a value and presses enter and has not selected a filed from the autocomplete list. Is this possible with the MassAutocomplete API?

Uncaught TypeError: m.suggest is not a function

Getting Uncaught TypeError: m.suggest is not a function when starting to type.

<div mass-autocomplete>
   <input class="form-control"  ng-model="client"  mass-autocomplete-item="client_names">
</div>  

Angular: v1.3.15

Feature Suggestion : Making the whole li element clickable

I was having trouble selecting suggestion items when clicked outside the text. I think it is better if you make your whole 'li' element clickable by simply moving ng-click directive to li

'<li ng-repeat="result in results" ng-if="$index > 0" ' +
      'class="ac-menu-item" ng-click="apply_selection($index)" ng-class="$index == selected_index ? \'ac-state-focus\': \'\'">' +
     '<span ng-bind-html="result.label"></span>' +
 '</li>'

Also, if the user types in the box but doesn't select from suggestions and the typed text matches with an item in suggestions, then we can force selection on blur.

It triggers a CSP error

When including MA on a page that has a fairly default content security policy (CSP) set, it triggers, because MA tries to inject a stylesheet into the page.

This is my CSP:

  <meta http-equiv=Content-Security-Policy content="default-src 'self'; script-src 'self' https://ajax.googleapis.com">

And the error thrown because of MA:

13:55:40.528 Content Security Policy: The page's settings blocked the loading of a resource at self ("default-src http://192.168.178.39:3000"). Source: position:absolute;. 1 192.168.178.39:3000

A possible solution is to respect the presence of the ng-csp directive (and settings thereof). To get styles onto an element, you'd need to somehow provide (perhaps simply through documentation) a separate piece of stylesheet that developers have to include in their existing stylesheets.

Force selection

Not sure if there is a clean way to do this but it would be nice to force a selection from the menu so the input is invalid if the input is not from the options.

Just something I think would be very useful .

On Destroy empty value

Thanks for the previous fix.

I am also getting errors with the following section when I navigate away from the page without putting anything into the input box.

     // Clear references and events.
        $scope.show_autocomplete = false;
        angular.element($window).unbind(EVENTS.RESIZE);
        value_watch();

Fixed with simple check.

     // Clear references and events.
        $scope.show_autocomplete = false;
        angular.element($window).unbind(EVENTS.RESIZE);
        if(typeof value_watch !== 'undefined'){
           value_watch();
        }

Using Controller As syntax

As recommended in most of the style guides I recently switched to the "controller as" syntax instead of $scope. This seems to be a problem because

 var options = scope[attrs.massAutocompleteItem];

seems to depend on the variable being bound to $scope.

Here is a plunkr that shows the behavior. I don't have a lot of time at the moment, but I will take a deeper look into it and maybe post a pull request with an alternative to the used way.

Edit: Ups, I guess issue #14 already covers that.

3 Letter minimum

Hello,

Would you be able to implement a minimum 3 letter parameter before rendering results please,

Thanks,

Angular Animate issue

I'm using Angular 1.2.8 (upgrading is not an option).

The very first time I enter text in the typeahead input, I receive the suggestion list just fine. If I click anywhere or type some more in the box after that, I get the following error:

TypeError: Cannot read property 'querySelectorAll' of undefined
    at cancelChildAnimations (angular-animate.js:807)

As a result, the suggestion list never updates (though the XHR which populates it returns its data just fine).

Here's a snippet of my template:

<label for="mgrFilter">Manager:</label>
<div mass-autocomplete>
    <input ng-model="manager" mass-autocomplete-item="macOptions" />
</div>

Here's a snippet of my controller:

var addSelection = function(selected) {
    $scope.manager = selected.value;
};

var managerTypeahead = function(term) {
    var deferred = $q.defer();

    managers.get(term).then(function(res) {
        var formatted = [];

        for (var i = 0; i < res.length; ++ i) {
            formatted.push({
                label: res[i].firstname + ' ' + res[i].lastname + ' (' + res[i].uid + ') ' + res[i].title,
                value: res[i].uid
            });
        }

        deferred.resolve(formatted);
    });

    return deferred.promise;
};

$scope.macOptions = {
    on_select: addSelection,
    on_error: console.log,
    suggest: managerTypeahead
};

I am using the workaround for a parent with position: fixed; presented in #13, but I doubt that has anything to do with it.

ng-model receive value of the input field even if empty

Dear @hakib,

first of all thanks for this great directive and the variety of options for its configuration.
Great job!

My goal is to bind the value of the input to a $scope.variable however it is not binding. My workaround as of now is to assign the term to a $scope.variable when fuzzy_suggest gets called

function fuzzy_suggest(term) {
            if (!term) {
                // filter assignment
                $scope.searchText = '';
                return [];
            }
            // filter assignment
            $scope.searchText = term;

this however only gets called as long as there is at least one character in the input field - not when the input is empty line 128.

function _suggest(term, target_element) {
        $scope.selected_index = 0;
        $scope.waiting_for_suggestion = true;
        if (typeof(term) === 'string' && term.length > 0) {

I am sure that I am missing something and would thus be grateful for a quick hint, what I can do to always extract the value of the input {{input}}

Thanks a lot.

Best,
Karl

Auto-select the first result

Can you add an option to make autocompleting easier, where the first suggested item is highlighted and can be selected immediately when you hit enter? Similar to typeahead-focus-first in ui-typeahead?

Up/Down key selection and mouse hover can end up with two highlights

If you press down arrow it highlights first row, if you now hover the mouse it highlights the different row, but it leaves the highlight on the row highlighted by the up/down arrow keys.

There should only be one highlighted row when you hover it should replace the previously highlighted row.

(if you press an up or down arrow this should start from currently highlighted row even if that was highlighted by mouse)

Maintaining existing results until new results received to prevent flashing

I've noticed that as the autocomplete loads results, as soon as the user starts typing again, they temporarily disappear until the new ones are loaded again. As a result, when typing a query and briefly pausing multiple times, the autocomplete keeps flashing on/off, which is distracting.

I think it'd be a good enhancement to (perhaps optionally?) keep the original results loaded in the autocomplete until the new results are ready.

(This is only noticeable when using remote results - local results load quickly enough that there's no flash.)

ng-model conflict?

Hi,

Thanks for this project, really useful!

One quick question: I saw that you apply the 'dot rule' in your examples and, indeed, when you have a ng-model without a dot, MassAutocomplete seems to mess up with the binding.
Is this a known / fixable issue?

Thanks in advance.

Suggestions stuck open on blur

If a user types in something that produces suggestions, like typing in 'co' in the first example in the demo, clicking away does not close the suggestions.

Hiding autocomplete when using a remote source and nothing has been selected.

I ran into this using a remote source, you can see the same behavior on the Remote source example.

When the user puts a value in the field and then clears it (backspace, cut) the ng-model value updates but the autocomplete does not. It remains visible and populated.

image

I found that changing part of the watch expression

from

 if (nv === last_selected_value) 
    return;

to

 if (nv === last_selected_value && nv !== undefined) 
    return;

Seemed to fix the issue, but I'm not confident in its place in the wider design of the plugin.

Clear model passing objects

I have this code:

$scope.autocompleteOptions = {
suggest: $scope.suggestContacts,
on_select: $scope.addContactToGuests
};

$scope.addContactToGuests = function(selected) {
$rootScope.contacts.push(selected.contact);
$scope.contact = undefined;
};

But the input wasnt cleaned before de selection. In the example page of MassAutocomplete, it works similary.

Whats wrong? Help me please.

Tests?

Are they in the pipeline?

Undefined on destroy

The library works great however when I leave the page that contains the module I am hit with

Cannot read property 'unbind' of undefined

I a assume this is because I am using controller as syntax.

IE9 not poping up list (doing select query) after initial selection.

Hi,

Tested Ie9 in my own code and on first State selection input on web site under examples. When you type "Ala", the select list appears and you can select as normal. When you click out of field and then back in, change the wording or retype from scratch the suggest doesnt seem to fire as it should.

Once you click out the suggest sometimes fires on blur which shouldnt be the case.

I`m trying to see what the issue is, but not making much progress.

Suggest box out of view

I'm implement this directive in a form inside a bootsrap modal. When I open it in a browser, the suggest box is nowhere to be seen although tab and up&down keys seem to work. Upon close inspection, I found out that the suggestion box is rendered out of view with large top and left style properties :

massautocomplete

As you can see above, the suggest box has the following style :

top : 852px
left : 583px

The box does appear as it should when I remove following lines from your __position_autocomplete()

function:

// container.style.top = rect.top + rect.height + scrollTop + 'px';
// container.style.left = rect.left + scrollLeft + 'px';

autocomplete

Is this a bug(maybe due to implementation within bootstrap modal that causes high top and left style values) or am I missing something ?

Prevent suggestion cycle when the value is the last value selected should be optional

I am facing a situation where:
1 - I need to refind the already selected value (because I can remove the selection outside the MassAutocomplete component)
What is blocking me is: Line 113

if (nv === last_selected_value)
    return;

I reset my ng-model to "", but the watcher is not triggered.
Is it possible to make it optional?
Thank you very much

on_select method not working when selecting suggestion from list

Greetings,

Based on the example for remote source example, the on_select method, when selecting a suggestion from the list, is not executed.
my question is: how can i check the selected suggestion?
using the example from lib's webpage, i made it like this:

$scope.ac_option_remote = { suggest: suggest_state_remote, on_error: console.log, on_select: function (selected) { $scope.selected_user = selected.data; console.log($scope.selected_user); } };

The console.log written, is not showing in developer console (im using gooogle chrome for testing).

edit: im thinking this is not a bug, but posting here could give me some lights about the possible issue.

best regards

'Suggest' function not triggered

Using your examples (http://hakib.github.io/MassAutocomplete/#examples), if input field is selected and you immediately paste a 'valid' value from your clipboard, the suggest function is not triggered. In result, the suggestion popup doesn't appear.

For example;

  1. copy 'Alabama' to your clipboard
  2. go to first example (i.e. suggest state).
  3. focus on the input field and immediately paste the value from your clipboard.

Actual Result: nothing happens.
Expected Result: suggestion popup to appear with one item (i.e. 'Alabama').

Note: if you undo (ctrl+z) and re-paste (ctrl+z), the suggestion popup appears as expected. The issue is appears to be related to the initial focus event.

This has been reproduced in Chrome (v 40.0.2214.115 m) & Firefox (v 37.0.2)

angular-mass-autocomplete with http request

I dont know how to make this code works properly

'home.controller('categoryController', function ($scope, $http, $sce, $q) {

    //var states = ['Alabama', 'Alaska', 'California', 'New york'];

    function suggest_state(term) {
        var q = term.toLowerCase().trim();
        var results = [];
        $http.get('/api/posts/findTags?name='+q).success(function(res){
            for (var i = 0; i < res.length && res.length < 10; i++) {
                results.push({ label: res[i].description, value: res[i].description });
            }
            return results;
        }).error(function(err){
            console.log(err);
        });

        return results;
    }

    function suggest_state_delimited(term) {
        var ix = term.lastIndexOf(','),
            lhs = term.substring(0, ix + 1),
            rhs = term.substring(ix + 1),
            suggestions = suggest_state(rhs);

        suggestions.forEach(function (s) {
            s.value = lhs + s.value;
        });

        return suggestions;
    };

    $scope.ac_option_delimited = {
        suggest: suggest_state_delimited
    };
});'

can you help me how to make it wait until loading data from the http get? it returns always before getting data...

thank you.

Button on suggestion box template

Hi,

Is there a way to add a clickable button on the suggestion box? I tried to create one but everytime I click on it the box was closing. Really need your help on this one. Thanks!

listing result template is not showing

I am implement this code on my ionic project.
suggestion seem well because went i push down button, it automatically fill the texbox.
but the preview template of list is not showing.
Here is my code

Html

<label mass-autocomplete class="item item-input-inset item-floating-label">                                  
          <span  class="input-label">City</span>                                                                                   
          <input type="text" ng-model="buildcity" mass-autocomplete-item="autocomplete_options" placeholder="City">                                              
</label>

js

var states = [];      

            CityService.getAll().success(function(data) {

                    for(var i=0, len=data.length; i<len; i++){                       
                        states.push(data[i].cityname);                 
                    }
            });
   function suggest_state(term) {
    var q = term.toLowerCase().trim();
    var results = [];

    // Find first 10 states that start with `term`.
    for (var i = 0; i < states.length && results.length < 10; i++) {
      var state = states[i];
      if (state.toLowerCase().indexOf(q) === 0)
        results.push({ label: state, value: state });
    }  
    return results;

  }

  $scope.autocomplete_options = {
    suggest: suggest_state
  };

Long press on menu item cause detach and the item is not selected

This is happening when the press is longer the debounce_blur.

The input losses focus which triggers detach. Since the item is pressed the click event does not invoke apply_selection. The apply selection does not regain focus back to the input field so detach considers it as if the input just lost focus and clears everything. When the click is finally invoking apply_selection the item is already detached and the selection is ignored.

This can be possibly be solved by using on-mousedown instead of ng-click but it needs to be tested on touch devices and there might be a usability issue as well.

Haki.

on_detach is not working

This is my code

Assigned to

this.$scope.coach_results = {
suggest: this.getCoachesList.bind(this),

        on_select (selected) {
            this.$scope.coach = selected.userId;
        },
        on_detach (selected) {
            this.$scope.coach = selected.userId; 
        }
    }
}

So the problem now I am facing is,

If I select item from suggestion box this.$scope.coach is filled with a value (selected.userId), but I clear the text box manually then the scope item is not getting cleared (having null or " "), so I used on_detach method but on blur it's not hitting the method.

Suggestions frozen open after detach

I've run into an odd case where my suggestion options open and freeze that after the field detaches.

Details:

  • I'm using the promise option for suggest
  • I have multiple auto complete fields in a row on the same form
  • It's an edit form so sometimes the inputs already have a full valid value in them

What happens:
If i start one field above the auto completes and tab through each of them:

  • tab into autocomplete field1
  • field1 attach fires
    • No dialog shows, i don't edit the text or anything.
  • tab into autocomplete field2
  • field1 detach fires
  • field1 suggest function is called and promise resolves
  • field1 autocomplete shows all the available options
  • field2 attach fires
  • tab into autocomplete field3
  • field2 detach fires
  • field2 suggest function is called and promise resolves
  • field2 autocomplete shows all the available options
  • field3 attach fires
  • tab into non auto complete next field
  • field3 detach fires
  • field3 suggest function is called and promise resolves
  • field3 autocomplete shows all the available options

At that point i can click any where the dialogs stay open. If i click on any of the open suggested options i get a console error TypeError: Cannot read property '0' of undefined from line 203 current_element[0].focus(); probably because the dom is showing but the controller is already detached.

If i tab/focus them again they attach, then once they detach again the dialog closes and the problem doesn't happen again. It seems to only happen on the first pass through.

on_detach doesn't pass me any thing or I can't call anything that I could use to clean up the suggested options right?

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.