The value selected is not being shown using uib-typeahead in the user interface

Within my AngularJS application, I am utilizing uib-typeahead to provide auto-suggestions in a text box. As I start typing, I can see the suggestions appearing. However, when I select one of the options, it does not display in the text field (ng-model).

I'm unsure whether the issue lies with the version of Bootstrap or Angular that I am using, or if there is an error in my code.

<input type="text" ng-model="selectedData" uib-typeahead="proDesc as mydata.proDescription for mydata in dataList | filter:$viewValue | orderBy:orderByStartsWith($viewValue)"/>

Here is the link to view my code:

http://plnkr.co/edit/s4ol9bkrcb16QV2pAikA?p=preview

Answer №1

The issue you're facing is that the entire object is being assigned to the $viewValue of the input when you select an option, rather than just the description property of the object.

If you want to assign the $viewValue from the description instead:

<input type="text" ng-model="selectedData" uib-typeahead="proDesc as mydata.proDescription for mydata in dataList | filter:$viewValue | orderBy:orderByStartsWith($viewValue)"/>

Change it to:

<input type="text" ng-model="selectedData" uib-typeahead="mydata.proDescription as mydata.proDescription for mydata in dataList | filter:$viewValue | orderBy:orderByStartsWith($viewValue)"/>

Answer №2

While cnorthfield's solution may be effective for some, I encountered issues in my own project where it did not work as expected. As a result, I came up with an alternative approach:

<input type="text"
ng-model="selectedData"
typeahead-input-formatter="$model.proDescription "
    uib-typeahead="mydata as mydata.proDescription for mydata in dataList | filter:$viewValue" /> 

It is important to note that in this scenario, selectedData will initially be an object in the array when a user selects an item from the list but will become a string if the user only types into the input box. To handle this distinction, you may need to implement an additional event listener, such as ng-blur, and within the listener, verify the model using an if block like so:

if (typeof selectedData === 'string') {
    for (var i in dataList) {
        if (dataList[i].proDescription === selectedData) {
            // perform necessary actions here
        }
    }
}

This workaround should be considered as a contingency plan in case cnorthfield's solution does not meet your requirements.

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

Customize date selection in Material UI React's DatePicker: A guide to formatting the date output

Is it possible to customize the date format from a datepicker to display only the date in YYYY-MM-DD format? The default datetime format currently being output is: Tue Feb 06 2018 00:00:00 GMT+0200 (FLE Standard Time) How can this date format be adjusted ...

Gather information from a customizable Bootstrap table and store it in an array

Currently, I have a bootstrap table configured with react-bootstrap-table-next, enabling users to edit cells and input their desired values. After completing the editing process, individuals can click on the "Submit" button to save the table values, which ...

What reasons underlie the existence of various methods for importing Modules in JavaScript?

I'm confused about the distinctions when it comes to importing a JavaScript module in various ways such as: CommonJS ES5 ES6 NodeJS Typescript What is the reason for having multiple methods of importing JavaScript modules? Is the concept of a "modu ...

Examining the performance of a React application through the use of Google Chrome

Currently, while working on my react application, I have been utilizing the chrome developer tool to monitor performance. However, I am having difficulty identifying which specific function is causing a high level of computational intensity. Could anyone ...

Exploring the World of Background Processes in Meteor

Is there a way to incorporate background tasks, possibly using a workers pool? I'm interested in exploring this concept further and potentially developing a package for it. Can you point me in the right direction? ...

Removing a dynamic TypeScript object key was successful

In TypeScript, there is a straightforward method to clone an object: const duplicate = {...original} You can also clone and update properties like this: const updatedDuplicate = {...original, property: 'value'} For instance, consider the foll ...

Connecting a button's action to a specific element in an array using AJAX and Firebase

I am currently working on a project that involves making an AJAX request from a social API and then appending the results with a button inside the div. This button is meant to save the corresponding item in the array to my Firebase database. For brevity, ...

Triggering an Angular AJAX call by selecting a radio button

I am currently working on implementing a CRUD functionality in my app for the admin console. My tech stack includes MongoDB, Spring, Bootstrap, and Angular. The interface consists of a list of radio buttons on the left side containing names of collections ...

Creating a search field in Bootstrap 4 that emulates material design, facing challenges with transition animations

I tried to create a material design search field using Bootstrap form input. While I was able to make it work, I noticed a small issue with the focus state. When I click inside the field, the underline animation runs smoothly. However, when I click outside ...

The list of items in a React Bootstrap Dropdown does not refresh when the state is changed

Trying to implement a dropdown with a list of checkboxes using react-bootstrap. The toggle event on the checkboxes works, but I'm facing an issue where the component is not re-rendered and the checkbox does not reflect the change. Check out the code ...

JQuery does not immediately update the input value

I'm working on a jQuery placeholder that mimics the behavior of default placeholders in Chrome and Firefox for browsers that don't support it. However, I'm facing an issue where the placeholder div's HTML doesn't change as quickly ...

Issue with Bootstrap dropdown functionality when used within a Horizontal description block

I'm struggling to get a dropdown menu to work properly within a horizontal description. The dropdown menu just won't toggle when clicked. <div class="container-fluid"> <div class="row vertical-align"> <dl class="dl-horizonta ...

What is the process for instructing Electron packager to utilize a personalized electron configuration file?

I have successfully managed to run my Angular 2 app through electron from the app's root folder. After building the app into the dist folder using the command: ng build --env=prod I simply execute: electron electron.conf.js Within the electron.con ...

What is the proper way to implement a $scope.$watch for a two-dimensional array in AngularJS?

Having trouble implementing an Angular watch on a multidimensional array I've got a screen where users can see two teams (outer array) with team sheets (inner array) for each team. They can drag and drop players to change the batting order. The batt ...

issues with updating a MongoDB collection

One challenge I'm facing with my social media app is that I have two separate collections - one for users and the other for user posts. When I update information in a user's collection, it should also reflect in the corresponding posts (as the po ...

Determining the equation from a string and converting it to an integer

I'm working with a table that contains formulas. For example, the formula is: (GP1/(GP1 + GP2))*100%. For my code using jQuery, I need to replace GP1 with the value from textbox1, GP2 with the value from textbox2, and remove the % symbol. My attemp ...

Applying Bootstrap's inline styling to adjust the width of a label

I'm having trouble adjusting the width of a Bootstrap label using inline styles. Here is my code: <td><span class="label label-info" style="width:30px; text-align:center; background-color:#6d8cbf"> TEXT </span></td> Unfort ...

Obtain the targeted tab name in Angular

I am working with a piece of html code that displays different pills, and I am trying to find a way to get the name of the selected one using Angular: <ul class="nav nav-pills mb-5 justify-content-center" id="pills-tab" role="tablist"> <li clas ...

How do I go about showing every character on a separate line using a for loop?

var input = prompt("What is Lance attempting to convey?"); //user enters any text for (var i = 0; i <= input.length; i++) { var output = input.charAt(i); if (output == "e" || output == "o" || output == "a" || output == "u") { outp ...

Update JavaScript variable value when there is a change in the onchange

Greetings, thank you for taking the time to read this. I am currently working with an input that includes a datepicker calendar. This calendar has variables called minDays and MaxDays which allow users to select a specific number of days. In my HTML form, ...