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

Platform error: Responses not specified for DIALOGFLOW_CONSOLE

I've been struggling with this issue for almost a day now and I'm at a loss for what else to try. For some reason, Dialogflow Fulfillment in Dialogflow ES is refusing to make any HTTP calls. Every time I attempt, I receive the same error message ...

Looking for a simple method to display a popover using conditional if/else statements?

On my website, I am utilizing JavaScript to determine the user's Facebook status. This includes checking if the user is already logged in and has allowed our app, if they are logged in but haven't authorized our application, or if they are not lo ...

Troubleshooting issues with Three.js and .obj file shadows

I've been diving into learning Thee.js, and while it's fairly straightforward, I've hit a roadblock with getting shadows to work. Despite setting castShadows, recieveShadows, and shadowMapEnabled to true in the appropriate places, shadows ar ...

I'm having issues with my countdown timer

Here is some of my JavaScript code: var run; var countdown; var count =14; var curImage = 1; function startAdPage() { run = setInterval("changeAd()"5000); countdown = setInterval("startCountdown()",1000); } function changeAd { switch (curImage) { case 1: ...

Is there a problem with textbox support for multi-line strings?

I'm having trouble getting a textbox to display multiple lines of text. For instance, when I copy three lines of text from Microsoft Word and paste it into the textbox, only the first line appears. The other two lines are not showing up, and I'm ...

Set the current time to ISO8601 format

I need assistance with creating a "time passed" counter for my website based on an API call that returns data in the following format: "created_at": "2018-05-16T14:00:00Z", What is the best approach to calculate and display the time that has passed since ...

Exploring nested static properties within TypeScript class structures

Check out this piece of code: class Hey { static a: string static b: string static c: string static setABC(a: string, b: string, c: string) { this.a = a this.b = b this.c = c return this } } class A { static prop1: Hey static ...

Objects in the array are failing to sort in the expected sequence

I am facing an issue with sorting an array of objects by a date property using the lodash function orderBy. I have tried to sort it in both ascending and descending order. var searchObj = [{id: 1, postDate: '2/24/2016 5:08 PM'}, ...

Discover every possible path combination

Looking to flatten an array of 1D arrays and simple elements, reporting all combinations until reaching a leaf "node." For example: // Given input array with single elements or 1D arrays: let input = [1, 2, [3, 4], [5, 6]]; The unfolding process splits pa ...

Prevent Mui popover from closing when clicking outside

Currently, I have implemented Mui Popover with ReactJS from the link here. One issue I am facing is that when a user clicks outside the popover, it automatically closes. Is there a way to disable this default behavior? Additionally, I would like to add a ...

What is the best way to make text appear as if it is floating in Jade or HTML?

Currently, I am facing an issue with a Jade file that displays an error message when a user tries to log in with incorrect credentials. The main problem is that this error message disrupts the alignment of everything else on the page, as it is just a regul ...

What is the best way to showcase a user's input in a webpage using vanilla javascript

Struggling with creating functionalities for a simple calculator using vanilla.js. Able to display numbers on click but facing issues with multiple clicks and deletion of values. Trying to use addeventlistener but encountering a Type Error "addeventliste ...

Anticipated a JavaScript module script, but the server returned a MIME type of text/html as well as text/css. No frameworks used, just pure JavaScript

I have been attempting to implement the color-calendar plugin by following their tutorial closely. I have replicated the code from both the DEMO and documentation, shown below: // js/calendar.js import Calendar from '../node_modules/color-calendar&ap ...

How to use the Enter key to submit a form in react.js with the help of "@material-ui/core/Button"

Here is the form I have created using the render method for user sign-in. <form onSubmit={this.handleSubmit}> <Avatar className={classes.avatar}> <LockOutlinedIcon /> </Avatar> <Typography component="h1" varia ...

Sending information through a form via a POST request after clicking on a hyperlink

I am attempting to submit a form using POST by clicking on a link and passing some hidden values. This is the code I'm currently using: $( document ).ready(function() { $('a#campoA').click(function() { $.post('testForm2.php', { ...

Linking Java objects with Node.js variables

In this snippet of code, I am utilizing the 'java' module in node.js to create Java objects. Specifically, I am creating four Java objects and aiming to consolidate them as a single object by using the variable 'args' to store these Jav ...

Is there a way to have my MUI Typography component display a unique image cursor when hovered over?

After some testing, I found that setting the cursor to cursor: pointer works perfectly fine. However, my goal is to use a custom image as a cursor. The image is saved in both my src and public folders, but I seem to be struggling with the syntax when using ...

"Looking to programmatically close a modal in JavaScript that was opened using the 'data-target' attribute? Here's how you can

I have a modal template embedded in the same HTML file as my controller. <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#modalDeleteItem">Delete selected item</button> < ...

Service in AngularJS with multiple functions

I seem to be encountering an issue with the service in my AngularJS application. I am receiving the following error: Uncaught SyntaxError: Unexpected identifier Error: [$injector:unpr] Unknown provider: NewContactDataProvider <- NewContactData This is ...

Using a pipe filter to implement a search feature in an Ionic search bar

Hey everyone, I'm facing a little issue here. I created a pipe filter to sort through some data, but now I need to include two more filters and I'm not sure how to go about it within this pipe. Below is an example of the pipe I have created: ...