Challenges arise when using ui-select with both multiple selection and asynchronous options

I'm encountering an issue with the ui-select directive (using AngularJS 1.6.4 and Ui-select 0.19.8).
You can find my created fiddle here.

The dropdown is supposed to display contacts when I type more than 3 characters, without any filtering applied at the moment. It works fine initially, but subsequent attempts do not show the dropdown.

I am using the asynchronous method for returning results, triggering my "refresh" function after a 1-second delay.

Could someone assist me in understanding why the dropdown does not appear after the first time?

(Additionally, if anyone knows why it's necessary to set display: block for the <ul> tag - see CSS section)

Thank you

HTML

<body ng-app="myApp">
  <div body ng-controller="ctrl as ctrl">

    <div class="element">
      Selected Contacts:<br>
      <div ng-repeat="contact in ctrl.contacts" class="contact">
        {{ contact }}
      </div>
    </div>

    <ui-select multiple ng-model="ctrl.contacts" class="element">
      <ui-select-match placeholder="Pick one...">{{$item}}</ui-select-match>
      <ui-select-choices
                         position="down"
                         refresh="ctrl.refreshContacts($select.search)"
                         refresh-delay="1000"
                         minimum-input-length="3"
                         repeat="person in ctrl.people">
        <div ng-bind-html="person | highlight: $select.search"></div>
      </ui-select-choices>
    </ui-select>

    <div class="element">
      <div ng-repeat="log in ctrl.logs track by $index" >
        <div>
          {{log}}
        </div>
      </div>
    </div>
  </div>
</body>

JS

var myApp = angular.module('myApp',  ['ngSanitize','ui.select']);

myApp.controller("ctrl", [function () {

  var ctrl = this;
  ctrl.logs=[];
  ctrl.refreshContacts = function(search) {
    var people = [
      "mickael",
      "pierre",
      "anna",
      "alice",
      "bob"
    ];
    ctrl.people = people;
    ctrl.logs.push("refreshContacts called")
  }

  ctrl.people = [];

}]);

CSS

.element {
  margin-bottom: 20px;
}

.contact {
  display: inline-block;
  margin: 5px;
  padding: 5px 8px;
  background: grey;
}

/* why do I need this ?! */
.ui-select-choices {
  display: block;
}

Answer №1

It seems there was a bug that arose when both minimum-input-length and refresh were used together. To tackle this issue, I decided to remove the minimum-input-length parameter and instead inserted an if statement inside the refresh function.

ctrl.refreshContacts = function(search) {
    if(search == undefined || search.length < 3){
        return;
    }
    else{
      people = [
        "mickael",
        "pierre",
        "anna",
        "alice",
        "bob"
      ];
      ctrl.people = people;
    }
  }

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best approach for finding the xPath of this specific element?

Take a look at this website Link I'm trying to capture the popup message on this site, but I can't seem to find the element for it in the code. Any ideas? ...

Can I extract JSON data from the AJAX response?

When receiving JSON data, such as in the example below, it is often necessary to separate each value into individual variables: var reviewDate ='2015-06-01T05:00:00Z' var developers ='Ankur Shah,Srikanth Vadlakonda,Tony Liu, Qiuming Jie&ap ...

Discover the method for obtaining a selected element in a bootstrap dropdown that is dynamically populated

Similar to the question asked on Stack Overflow about how to display the selected item in a Bootstrap button dropdown title, the difference here is that the dropdown list is populated through an ajax response. The issue arises when trying to handle click ...

The <a> tag does not lead to a different webpage and cannot be clicked on

I have developed a web component that includes a method to generate a copyright string: '<p>Copyright © 2020 John Doe<a href="https://www.example.com">. Terms of Use</a></p>' After creating the string, I conver ...

Sending Email Form in PHP using JQuery and Ajax for seamless user experience

Looking to create an email form in HTML with PHP, but running into the issue of the page reloading after submitting? Many people turn to jQuery and AJAX to solve this problem. While you may have come across solutions on Stack Overflow, as a non-native Engl ...

What is the best way to manage undefined status in react after the user chooses to cancel selecting a file?

Having an issue with my simple Input file type in React. I'm storing the selected file in state, but when I click the clear button, the state doesn't actually get cleared. This leads to {selectedFile.name} throwing an undefined error if the user ...

Issue with bookmarklet compatibility on mobile browsers like iOS and Android

Here is the bookmarklet code I have: javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.js";c.onload=c.onreadystate ...

Mastering the use of useMasterKey in Parse with Node.js: A guide

Greetings everyone, I have developed my app using parse.com but now I need to utilize the master key as some users have administrative roles. Initially, I attempted to use the JS SDK but was advised to switch to Cloud Code. So, I tried using Express and ...

Update the webpage post a database entry without relying on the setTimeout() function in Javascript

Is there a method to automatically refresh the page after a new entry in the database without relying on Javascript's setTimeout or setInterval functions? Could an AJAX function or a MySQL function accomplish this task instead? Must we continuously ...

Enhance your viewing experience with the Zoom feature that activates when

I recently noticed on that I am able to zoom/enlarge a photo by clicking on it. Is there a way for me to incorporate this feature without purchasing the entire theme? While I understand the theme is designed for purchase, I only need this specific functi ...

Leveraging functions with Ng-Repeat

I am currently dealing with two different arrays of objects. The first array contains a list of permissions groups, while the second array consists of user groups. My main goal is to compare the Group Owner (which is represented by ID 70) with the list of ...

Attempting to employ the .reduce method on an object

Currently, I am faced with the task of summing a nested value for all objects within an object. The structure of my object is as follows: const json = [ { "other_sum": "1", "summary": { "calculations" ...

Steps to eliminate a choice from the MUI Datagrid Column Show/Hide feature

I am attempting to customize which columns are displayed on the <GridToolbarColumnsButton/> component within the MUI Datagrid toolbar (refer to the image below) https://i.stack.imgur.com/joZUg.jpg Potential solution: I have been exploring the AP ...

Two ng-click events are triggered within a nested ng-click

I am facing an issue with using the ng-click within a nested list under another list that also has a ng-click event. Here is my code snippet: <ul> <li ng-repeat="facet in node.Facets" ng-click="updateNav(facet.Action)" ng-cloak & ...

Incorporating Mongoose Schema structures into my NextJS webpage

I am new to NextJS and seeking assistance with an issue I am facing. I have defined 2 Mongoose schemas and using one on my page without any problems. However, when I try to import the second schema, my page fails to render and throws an error. Regardless ...

Loading an ASP.net page on the client side

Can someone tell me the event for pageload on clientside? function onPageLoad() { setSelectedIndexTo(1); } I attempted to do this, however no changes occur. Appreciate any help. Thanks! ...

Is there a way to display a button and text upon hovering over an image without using JQuery?

On my current WordPress project, I am faced with the task of creating a gallery that displays text and a button when users hover over an image. I have attempted to use a:hover but have only been able to make limited modifications. Can anyone provide guid ...

The controller is not receiving the isolated scope value

I have implemented angular-slider.js on a webpage where a server request is triggered upon changing the slider's value. I am looking to delay this action until the user releases the mouse button, specifically during onmouseup event. Incorporating thi ...

Adding an extra element to the <MuiThemeProvider /> causes the page to display as blank with no error notifications

After incorporating Material UI into my Meteor application via npm install --save material ui I successfully implemented the <Header /> component in my app.js file. However, when I try to add additional components, such as localhost:3000, all I see ...