When an input is double-clicked, the message"[object object]" appears on the screen

Here is the structure of the template used for the directive. Our code fetches data from a service which contains all the details of a specific individual. We display only the first name, last name, and either designation or company affiliation from that data.

<div ng-if="model" class="entry-added">
  <span class="form-control"><b>{{model.fullName}}</b>, <br/><span class="small-font">{{(model.designation)?model.designation:model.companyAffiliation}}</span></span>
  <a ng-click="removePerson()" class="action-remove"><i class="fa fa-remove"></i></a>
</div>

<div ng-show="!model" class="input-group">
  <input type="text"
         class="form-control"
         name="{{name}}"
         id="{{name}}"
         placeholder="{{placeholder}}"
         ng-required="{{isRequired}}"
         typeahead-on-select = "change($item, $model, $label)"
         ng-model="model"
         typeahead-min-length="3",
         typeahead="suggestion for suggestion in searchEmployees($viewValue)"
         typeahead-template-url="typeAheadTemplate.html"
         typeahead-loading="searching"
         typeahead-editable="false">

<script type="text/ng-template" id="typeAheadTemplate.html">
  <a class="ui-corner-all dropdown" tabindex="-1">
    <div class="col-md-2"><img class="dropdown-image" ng-src="https://people.***.com/Photos?empno={{match.model.employeeNumber}}"></div>
    <div>
      <div bind-html-unsafe="match.model.fullName"></div>
      <div bind-html-unsafe="match.model.designation"></div>
    </div>
  </a>
</script>

A custom directive is being utilized to present a search field. However, the drop-down section currently displays as [object object].

Directive

// The backend structure includes taxDeptContact as a Person type object
/*
Directive code
 */
(function () {
  'use strict';
  angular.module('treasuryApp.directives').directive('employeeSearch', employeeSearch);
  employeeSearch.$inject = ['$resource', '$rootScope', 'ErrorHandler'];

  function employeeSearch($resource, $rootScope, ErrorHandler) {
    return {
      restrict: 'E',
      require: '^form',
      scope: {
        model: "=",
        isRequired: '@',
        submitted: "=",
        onSelect: '&',
        name: '@',
        index:'@'
      },
      link: function(scope, el, attrs, formCtrl) {
        // Set required attribute for dynamic validation adjustments
        scope.searchEmployees = function (searchTerm) {
          var users = [];
          var myResult = [];
          var result = $resource($rootScope.REST_URL + "/user/getEmployees", {term: searchTerm}).query().$promise.then(function (value) {

            //console.log(value)
            $.each(value, function(i, o) {
              users.push(o);
            });
            return users;
          });
          return result;
        }
        scope.removePerson = function() {
          scope.model=null;
        }
        scope.userNotSelectedFromTypeahead = function(name) {
          if(undefined === formCtrl[name]) {
            return false;
          }
          return formCtrl[name].$error.editable;
        };
        scope.change = function(item, model, label) {
            scope.model = item
            scope.onSelect(
              {name: scope.name, person: scope.model});
        },

      templateUrl: 'app/components/common/directives/employee-search.tpl.html'
    };
  }
})();

View incorporating the directive

<div class="form-group">
    <label class="col-sm-3>Tax Dept Contact</label>
    <div class="col-sm-4">
        <employee-search model="reqCtrl.requestObj.taxDepartmentContact" name="taxDeptContact" is-required="false" submitted="reqCtrl.submitted"/>
    </div>
</div>

Error Image Link https://i.stack.imgur.com/9eP6K.png

Answer №1

This area seems to be causing some issues for you

search for item in getResults($viewValue)

item is currently retrieving the entire object. Have you considered displaying a specific attribute of item?

For instance: if there is an attribute called item.name, you could use the following syntax:

search for item.name for item in getResults($viewValue)

Answer №2

At last found the solution: I added autocomplete="off" in my custom directive and problem solved

<input type="text" autocomplete="off" />

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

Ways to Manage modals responses as services in AngularJS

I am a beginner in the world of JavaScript and AngularJS. I am fascinated by some of the concepts within JS, like trying to create a modal service using the example I found online. I am eager to delve deeper into what exactly is happening under the hood, e ...

Troubleshooting Angular Unit Tests with Karma and Jasmine

I'm having difficulties writing unit tests for my new Angular Application. Here is the controller I am working on. 'use strict'; angular.module('nileLeApp') .controller('RegisterController', function ($scope, $translate ...

Java Applet for capturing specific sections of a webpage to create a screenshot

Does anyone know of a way (applet or something else) to capture a screenshot of the content within a specific div on a webpage? I came across this Java code for capturing a screenshot of the entire screen: import java.awt.AWTException; import java.awt.Re ...

"Facing a dilemma with Javascript's Facebox getElementById function - not fetching any

Utilizing facebox, I am initiating a small modal dialog with a form and attempting to retrieve the value from a text field on that form using javascript. Below is the HTML code: <div id="dialog-form95" style="display:none"> <div class="block"> ...

Angular dynamically filling in a table with incomplete object data

I am currently working on a scientific project that involves displaying large amounts of data in tables. The experiments I'm working with have timestamps that follow this format: interface TimeData { time: string; data: {SD: string, SEM: string ...

"Is there a way to alter the background color of the second span within a Bootstrap row

I currently have 4 WordPress services in a loop, and I am trying to change the background color of the second service. However, when I try to apply the CSS background property, it ends up affecting all of the services. Here is my template code: <div ...

Utilize custom fonts from your local directory within a Vite Vue3 project

Inside my main.scss file, I am loading local fonts from the assets/styles/fonts folder: @font-face { font-family: 'Opensans-Bold'; font-style: normal; src: local('Opensans-Bold'), url(./fonts/OpenSans-Bold.ttf) format('truety ...

The alignment of inline-block elements is not being maintained on the same line

Here's a question I have about my embedded form. Why does the display property of inline-block make the "submit" and "terms" elements appear higher than the email field? And more importantly, how can I fix this issue? I've attempted to use the t ...

Include a horizontal line divider between each row of items that wrap to the next line

I am utilizing CSS flexbox to arrange a variable number of items in rows, wrapping around to additional rows as necessary. My query is, can a horizontal line be inserted between each of the rows? Here you can find a basic example of what I am working on. ...

Scaling Vuetify icons dimensions

During the development of an app using Vuetify, I encountered challenges in changing the default colors set by Vuetify. After some trial and error, I came across a solution on: https://github.com/vuetifyjs/vuetify/issues/299 The solution involved adding ...

Is there a way to adjust only the height of a responsive image?

Increasing the Height of an Image on a Mobile Device! I have an image that displays as the header of my website. When I resize the window to mobile format, the image resizes too. However, I want the height of the header image to be longer! Is this possibl ...

implementing a jQuery draggable Scrollbar

I'm looking to replicate the feature on this website where they have a scrollable bar at the bottom with a handle that you drag to navigate through the page. I've been searching but can't seem to find anything similar. ...

What is the best way to split a Bootstrap col-md div in half vertically?

I am attempting to create the following layout using the Bootstrap grid system. Within a container <div class="row">, there are two divs occupying half of the width each (<div1> and <div2>). The height of <div1> will vary based on t ...

Resolving the issue of "Cannot set properties of null (setting 'innerHTML') at HTMLInputElement.loader" involves identifying the root cause and implementing

Need assistance with this code. Although I believe everything is correct, it still isn't working as expected. The error mentioned in the title comes up whenever I try to use it. I've made multiple modifications to the code but it's still not ...

Searching and categorizing information within a table using jQuery

Can someone help me with merging my html and jquery code for type and filter table data, as well as tag data in the same input box? I have the code for both functionalities separately (http://jsfiddle.net/tutorialdrive/YM488/), but I want to combine them. ...

"Can anyone provide guidance on how to initiate a css 3d animation by clicking a button

Currently, I am developing a folding hide/show animation that can be triggered using Javascript. If you would like to take a look at the code and see a working example, please visit this link: You can also view just the gist here: https://gist.github.com ...

Tips on sending filter parameters from AngularJS to Spring RestController using @MatrixVariable

I’m struggling to figure out how to use $http.get in AngularJS to pass filter parameters. The URL is: http://localhost:8080/template/users/query;username=abcd;firstName=ding... The RestController looks like this: @RequestMapping(value={"/users/{query ...

Reducing image size using CSS can result in blurry images on multiple web browsers

Encountering challenges with downscaled images in multiple browsers... The images must be downscaled to adapt to the browser size. Here is the code snippet: #pic-holder img { -moz-transform: rotate(0deg); /*image-rendering:-webkit-optimize-contras ...

Struggling to display the Three.js LightMap?

I'm having trouble getting the lightMap to show on my mesh. Here's the code I'm using: loader.load('model.ctm', function (geometry) { var lm = THREE.ImageUtils.loadTexture('lm.jpg'); var m = THREE.ImageUtils.loadT ...

What is the best technique for positioning a div using the ELEMENT_NODE method?

  #top { height: .5rem; padding-left: 2.7rem; line-height: .5rem; color: #666; font-size: .12rem; position: relative; background-color: rgb(241, 241, 241); } #top div { position: ...