Utilizing numerous occurrences of my personalized Angular JS Directive within the identical form

I've been struggling to find a solution for this particular issue.

On my webpage, I have two instances of a directive that are supposed to set values for two different text fields. However, when I select one value, the other field automatically changes to the same value.

I would greatly appreciate any insights or suggestions to help me resolve this problem as I've been stuck on it for quite some time now.

I've attempted using ngModel Isolate scope and other methods but haven't been successful so far.

Every time I change one value, it impacts the other field as well.

To provide more context, I've created a demo on [Plunker] http://plnkr.co/edit/xwsrThvbVsIXPotRHc7o, although I couldn't get that to work either.

Below is a snippet from my template:

      <input class="form-control" id="lovdat" name="lov" ng-dblclick="dblClick()" ng-keyup="keyUp($event)" ng-model="lovval.displayval"
       type="text">

And here is the code from my directive:

var app = angular.module('plunker', ['LOVDirective']);

app.controller('MainCtrl', function($scope) {
$scope.officeMaster = {

officeId: "",
officeName: "",
company: "",
companyId: "",
officeManager: "",
officeManagerId: "",
officeLocation: "",
isactive: ""

};
 $scope.lovvalemp = {
  displayval: "",
  dataval: ""
    }
  $scope.lovvalcomp = {
    displayval: "",
    dataval: ""
  }
});

angular.module('LOVDirective', [])
  .directive('Lov', [function() {
    return {
      scope: {
        label: '@', 
        changeCallback: '&',
        lovval: '=info'

      },
      restrict: 'EA',

      replace: true, 
      templateUrl: 'template.html',


      link: function(scope, element, attr, ctrl) {
        scope.param = {
          "LOVType": attr.gacLovType,
          "LOVSearchString": "",
          "LOVSearchCriteria": ""
        };

        scope.alertModalPopup = {};
        scope.alertModalPopup.selectedItem = "";

        scope.dblClick = function() {
          selectdata();
        };

        scope.selectdata = function() {
          scope.lovval.displayval = attr.gacLovType + "Sherry";
          scope.lovval.dataval = attr.gacLovType + "1";
          lovval = scope.lovval;
        };
      }

    };
  }]);

Finally, in my Index.html file:

  <div class="form-group">
      <label class="control-label required" for="txthead">Manager</label>
      <lov ng-model="officeMaster.officeManager" data-gac-lov-type="EMPLOV" info="lovvalemp"></lov>
    </div>
    <div class="form-group">
      <label class="control-label required" for="txtoffice">Company</label>
      <lov ng-model="officeMaster.company" data-gac-lov-type="CMPLOV" info="lovvalcomp"></lov>

    </div>

Answer №1

I won't provide you with a direct code solution, but I can steer you in the right direction.

Based on the comments, it seems like your issue lies with the jQuery selectors - $('#lovPopup') and $("#lovGrid") are targeting the first elements in the DOM. Have you noticed that the popup appearing is actually below the first input? By examining the HTML, it's clear that the second form is always hidden, regardless of which input field you double-click on, due to improper jQuery selectors.

In my updated plunker, I removed most of the jQuery and utilized ng-show to toggle the modal visibility. However, you'll need to figure out how to properly handle the kendo-grid. Take a look at this example of using kendo-ui in angular.

Check out the updated plunker here: http://plnkr.co/edit/3FhBL2ZtkxHOO6EJ3gKF?p=preview

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

Accessing a webpage by directly pasting the URL into the address bar is functioning properly, but is

I'm facing an issue with accessing files from a vendor's application. When I directly enter the endpoints into the browser's address bar, the file opens up without any problems. However, when I try to access them using jQuery AJAX, I receive ...

Creating a stylish gradient text color with Material-UI's <Typography /> component

Is there a way to apply a gradient font color to a <Typography /> component? I've attempted the following: const CustomColor = withStyles({ root: { fontColor: "-webkit-linear-gradient(45deg, #FE6B8B 30%, #FF8E53 90%)", }, })(T ...

The modal in Angular UI Bootstrap is returning an undefined result

Currently, I am in the process of developing an app that involves loading a modal upon clicking a button within an ng-grid row. The modal is correctly displayed with all the necessary data, but unfortunately, I am facing an issue when attempting to retriev ...

Can a pledge be honored at a precise moment?

I have implemented transitions on my web page. When clicked, everything fades out to an opacity of 0 over a duration of 1 second. Then, a new page is swapped in and everything fades back in to an opacity of 1 over another 1-second duration. The issue aris ...

Information is not appearing in the dropdown menu

As a beginner in JavaScript, this is my first program. I have written HTML and JavaScript code to display data in a dropdown menu from a Python Django database. However, when I run it, the data is not showing up. Here is my code: <!DOCTYPE html> < ...

Animation of scrolling in a horizontal layout

Currently, I am utilizing ng-repeat 1.4 to dynamically generate elements within a div that has polymer shadow classes and uses the 'layout horizontal' style, resulting in code similar to: <div class='layout horizontal'> < ...

Use a filter to narrow down results based on a column containing comma-separated values, as well as another specified

I am encountering an issue when attempting to apply filters on multiple columns within an object. The filters need to be applied based on the selection made in two drop-downs: one is directly linked to the ID, while the other holds the name but needs to be ...

Preventing mouse clicks on checkboxes and triggering events using JavaScript - a complete guide

We have a Table grid with multiple columns, one of which is a Select Box (CheckBox). The expected behavior is that when a row is clicked, the respective CheckBox should get checked, and clicking on the CheckBox itself should update it. I tried implementin ...

Using React.PureComponent, the list component efficiently renders each item with optimized performance

We've developed a reusable list component in ReactJS. To address performance concerns, we decided to incorporate the shouldComponentUpdate method to dictate when our list component should re-render. public shouldComponentUpdate(nextProps: TreeItemInt ...

Issue: Infinite loops detected in AJAX functions

I am using $.get methods in the following code snippet: $.get("/url" , function(z) { var a = $(z).find("span"); for (var i = 0 ; i<a.length; i++){ var v = $(a).eq(i).children("strong:first").text(); alert(v); } }); However, the s ...

Using the base tag in Angular HTML5 mode can cause script links to break

Issue Following the configuration of a base tag to enable Angular 1.x in HTML5 mode, encountering an error where the browser (Chrome) sends requests to an incorrect path for scripts when directly accessing the app via localhost:3000/resource/id. Specific ...

What is the method to provide function parameters without executing the function?

I'm searching for a solution to obtain a function that requires a parameter without actually invoking the function. Example of current malfunctioning code: const _validations = { userID: (req) => check('userID').isString().isUUID(&apo ...

What is the best way to assign user input to my JavaScript variables?

As a newcomer to programming, I am eager to develop an app that utilizes the numerical values inputted by customers as variables for calculations. How can I extract the value from an input using JavaScript? For instance, how can I subtract one input value ...

Flickering observed in AngularJS UI-Router when navigating to a new route

In my AngularJS ui-router setup, I am facing an issue with flickering during state changes while checking the authentication state. When a user is logged in, the URL /#/ is protected and redirects to /#/home. However, there is a brief flicker where the c ...

Using data from an API, I am implementing JavaScript validation for my dropdown select menu

Using an API, I am able to access information about the city's subway stations through a select option. Currently, I can only display details about one station (Balard). However, I would like to be able to display information about other stations tha ...

Is there a way to implement full-page scrolling in Vue?

Looking for a Vue equivalent of the fullpage.js library. Need a component that allows scrolling through elements similar to fullpage.js. ...

In the JavaScript example provided, do child classes inherit their parent class prototype?

Here's the code I'm working with: class Rectangle { constructor(w, h) { this.w = w; this.h = h; } } Rectangle.prototype.area = function () { return (this.w * this.h); }; class Square extends Rectangle { construct ...

Is there a way to send me the result of the radio input (Yes/No) via email?

Is it feasible to send the results of a radio input (Yes/No) back to my email directly using HTML, CSS, and Javascript? ...

angular trustAsHtml does not automatically insert content

Two divs are present on the page. Upon clicking button1, an iframe is loaded into div1. The same applies to button2 and div2. These iframes are loaded via ajax and trusted using $sce.trustAsHtml. This is how the HTML looks: <div ng-bind-html="video.tru ...

Leveraging the power of Express.js, transmit local data alongside a

Why can't I display the active user in my view using plain HTML when console log shows it? Here is the code snippet: app.post('/', function (req, res) { var user = { user : req.body.username }; res.render('doctor_hagfish/pets&ap ...