Passing objects to an AngularJS form using UIB TypeAhead without two-way binding

In my current situation, I am encountering an issue with a typeahead feature on a repeating form element that consists of 5 input fields. While everything functions correctly when selecting results and populating the input fields, the model does not get updated as expected.

The typeahead setup is as follows:

<input type="search"
                                       ng-model="product"
                                       ng-model-options="{ getterSetter: true }"
                                       typeahead-editable="true"
                                       typeahead-click-open
                                       typeahead-loading="product_Loading"
                                       typeahead-input-formatter="inputFormatter($model)"
                                       typeahead-min-length="0"
                                       typeahead-select-on-exact="true"
                                       typeahead-no-results="noResults"
                                       typeahead-popup-template-url="/app/directives/typeaheadDefaultTemplate.html"
                                       typeahead-popup-template-new="products"
                                       autocomplete="off"
                                       placeholder="Select product"
                                       uib-typeahead="tyh as tyh.name for tyh in typeahead($viewValue, 'products')"
                                       class="form-control no-border-right">

Here are the recipients for the selected element:

<input name="qty" type="number" ng-model="product.qty" class="qty form-control text-right" value="1">
<input name="price" type="number" ng-model="product.price" class="price form-control text-right" placeholder="0.00">
<input name="total" value="0.00" disabled type="number" class="total form-control text-right">

Answer №1

Make sure to include an ng-model attribute for the 3rd input field.

When using typeahead, the ng-model is crucial as it represents the search query. To ensure that updates to the product object are reflected in other inputs, you will need to handle this programmatically, either on select or focus events.

To make this work seamlessly with your typeahead, change the model to productSearchModel and add the following attribute:

typeahead-on-select="onSelect($item, $model, $label, $event); productSearchModel = '';"

Additionally, include a similar function in your controller:

 $scope.onSelect = function (item, model, label, event) {
    product = model;
};

This function will be triggered when a user selects an option.

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 are some ways to reduce the delay of Dark mode on a website?

Can anyone help me optimize the speed at which dark mode is applied on my website? Currently, there seems to be a delay between page load and the dark mode taking effect. Below is the jQuery.js code I am using: onload = function () { if (localStorage. ...

Hiding the C3 tooltip after engaging with it

I'm currently expanding my knowledge on utilizing C3.js for creating charts, and one aspect I'm focusing on is enhancing the tooltip functionality. Typically, C3 tooltips only appear when you hover over data points as demonstrated in this example ...

The Google Picker API encounters a server error when attempting to retrieve the OAuth token after being released as a private add-on

Recently, I encountered a puzzling issue with my script that utilizes the Google Picker API. During testing, everything worked flawlessly until I decided to publish it as a private add-on. From that point on, the script's getOAuthToken function starte ...

Encountering the React.Children.only error while trying to use the <Link> component in Next.js

I'm encountering an issue with the code below: Error: React.Children.only expected to receive a single React element child. While trying to troubleshoot, I noticed that it only allows me to have one header under the link. <div className="co ...

Exploring the integration of ng-model within a select box or its options in AngularJS

I have a table with data including a select box. Instead of using {{n.triggerOn}, I want to bind the data using ng-model. The code below works when I use <option value="">{{n.triggerOn}}</option>. However, I would like to bind the data using ng ...

The function designed to create in-line TailwindCSS classNames may work inconsistently in React and NextJS environments

Currently, I am utilizing TailwindCSS to style a web application. One frustrating aspect is that when attempting to add before: and after: pseudo-elements, it must be done individually. For instance, take the navigation drop-down button styling: <span ...

arrange by numerical values using angularjs

My dataset consists of an array of objects... var userObjects =[ {userName: bob, age: "25", gender: "m" }, {userName: bill, age: "15", gender: "m" }, {userName: jen, age: "45", gender: "f" }, ] Within my HTML, I have implemented an ng-repeat functi ...

Tips on linking a condition-reaction to document.querySelector

I am struggling to connect the condition-reactions to the input id of passid. I am unsure where to place the document.querySelector() method in order to link the indexed conditions correctly. Below is the code snippet: <!doctype html> <html> ...

React array mapping issue does not produce any error message

I have exhaustively searched through every answer on Stack Overflow in hopes of finding a solution to my problem. However, I find myself at an impasse as there are no error messages appearing in the console. It seems that there is a hidden bug eluding my d ...

Refresh the form fields using PHP_SELF after submission

How can I pass a calculated value to another form field using php_self to submit a form on the same page? The $title_insurance field is not getting populated, any suggestions on what might be causing this? <?php if(isset($_POST['submit'])) { ...

The value of ng-model is consistently stored as a string, regardless of whether the input is a number or

<div> <input type="text" ng-model="test"/> </div> When a value is entered into the input field with the ng-model "test", it is always treated as a String type, even if it is a valid number. However, I am looking for a way to determine th ...

An error occurs even before any Components are rendered, with a TypeError stating that the property 'type' cannot be read because it is undefined

I'm facing an issue with my Redux App where the first component (App.js) is not rendering due to continuous errors. The reducer mentioned below is being triggered at some point without any action, causing the compiler to interpret action as null and f ...

Unleashing the Power: Crafting Impeccable For Loops

After running the select query in the "get-employee.php" page, I obtained the answer for this page. Then, I returned the data to the previous page (home.php). On this page, I added a for loop in JavaScript before the tag with the class "col-md-3". Within t ...

Utilizing Vue: Attaching click event to dynamically added elements

I am working on a Vue application that retrieves HTML content from an API. This HTML contains blocks with the class <div class="play-video">...</div> Using axios to call the API and a promise, I insert the content into the DOM like this: < ...

Guide on Retrieving the Most Recent Database Entry with the Aid of AngularJS and PHP

I have developed two unique web pages. One is called BookTicket which contains a form with two buttons. The first button submits the form and stores the information in a database, while the second button navigates to a payment page. The other page is cal ...

Shuffle letters in a word when hovered over, then unscramble them back to their original order

I have noticed a fascinating effect on several websites. To give you an idea, here are two websites that showcase this effect: Locomotive and TUX. Locomotive is particularly interesting to look at as the desired effect can be seen immediately when hovering ...

Having issues with the latest version of Fabric JS code running properly

Hello, I stumbled upon this JS fiddle (http://jsfiddle.net/efmbrm4v/2/) and I really need something similar to function properly. The fiddle uses an older version of fabric js (1.4.0) and I'm having trouble getting it to work with the newer versions ( ...

ERROR: Expo TaskManager Notifications [TypeError: Attempting to call an undefined function (near '...Notifications.presentLocalNotificationAsync...')]

I'm currently trying to figure out how to send notifications whenever a task is triggered, but I keep encountering an error that I can't seem to fix. Here's the error message: TaskManager: Task "background-fetch" failed:, [TypeError: unde ...

It seems that the `to` required prop was missing in the `Link` component of React-Router

Currently, I am facing an issue while trying to integrate react-router. The error message I'm encountering is: Failed propType: Required prop to was not specified in Link. Check the render method of app. Unfortunately, I am unable to pinpoint ex ...

The Data Table experiences intermittent hanging issues (Table is empty) when sorting or loading data with Knockout binding

While working on a project, I encountered an issue with binding data to a table using Knockout JS and the JQuery/Bootstrap based; Data Table API. The problem was that the table would become unresponsive at times when sorted or loaded, without any errors be ...