The Firefox dropdown menu constantly reverts back to the default option because of JavaScript running in AngularJS

I am currently developing an AngularJS app and encountering issues with select dropdown menus specifically in Firefox.

Whenever I click on a select menu and hover over the options, it automatically resets the selected option back to the default/first option instead of the one my cursor is on. This problem becomes more challenging when dealing with a large number of options as it makes it hard to choose the correct one.

It seems that this issue arises due to the requirement of JavaScript to update the screen every second in the app.

Interestingly, I do not face this problem when using Chrome or Safari browsers.

Is there a solution available to fix this behavior in Firefox?

Check out the demo here.

index.html

<!DOCTYPE html>
<html ng-app="myapp">
  <head>
    <script data-require="<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="bcddd2dbc9d0ddce92d6cffc8d928c928b">[email protected]</a>" data-semver="1.0.7" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"></script>
    <link href="style.css" rel="stylesheet" />
    <script src="script.js"></script>
  </head>

  <body ng-controller="ctrl">
    <div ng-init="updatetimer()">
    <div>seconds: {{counter}}</div>
    <select ng-model="something" ng-options="n.name for n in namelist">
      <option value="">select person</option>    
    </select>
    </div>
  </body>
</html>

script.js

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

var ctrl = ['$scope', '$timeout', function($scope, $timeout) {

    $scope.counter=0;

    $scope.namelist = [
      {name: "Name1"}, {name: "Name2"}, {name: "Name3"}, {name: "Name4"}, {name: "Name5"},
      {name: "Name6"}, {name: "Name7"}, {name: "Name8"}, {name: "Name9"}, {name: "Name10"},
      {name: "Name11"}, {name: "Name12"}, {name: "Name13"}, {name: "Name14"},
      {name: "Name15"}, {name: "Name16"}, {name: "Name17"}, {name: "Name18"},
      {name: "Name19"}, {name: "Name20"}, {name: "Name21"}, {name: "Name22"},
      {name: "Name23"}, {name: "Name24"}, {name: "Name25"}, {name: "Name26"},
      {name: "Name27"}, {name: "Name28"}, {name: "Name29"}, {name: "Name30"}
   ];

  $scope.updatetimer = function() {

    var updater = function() {
      $scope.counter++;
      $timeout(updater, 1000);
    }
    updater();
  };

}];

Answer №1

It appears that the problem lies in generating the 'option' elements using ng-options.

To investigate further, I have made some modifications to the code.

Please refer to the plunkr demonstration below.

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

In order to address the issue, I have shifted the option creation logic to utilize ng-repeat. This adjustment should resolve the current problem.

Answer №3

There are still individuals who may encounter this issue.

Here is the solution:

 if (currentOption.id !== option.id) {
    lastElement.val(currentOption.id = option.id);
 }
-if (currentOption.element.selected !== option.selected) {
+if (currentOption.selected !== option.selected) {
      lastElement.prop('selected', (currentOption.selected = option.selected));
 }
} else {

Integrate this patch directly into the angular core. This glitch continues to persist in version 1.2.8

Answer №4

This problem is related to an outdated version of AngularJS, specifically versions before 1.0.7. The issue has been resolved in version 1.0.7, so if you are using a version older than that, you will encounter the same problem.

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

Display a comprehensive inventory of all bot commands within a designated category

When a user executes a command, I have various commands categorized and would like to present them accordingly. For instance, consider the following command: const Discord = require('discord.js') const { MessageEmbed } = require('discord.js& ...

Connection Among Angular Modules

I am currently encountering an issue with Dependency Injection between modules. One of my modules implements a directive that I need to utilize in other applications. To incorporate the dependency from this module into another app declaration, I used the ...

How can refs be applied effectively in React applications?

I've been thinking about the role of refs in React and how they can address certain challenges for developers. However, I have found that the explanations provided in the React documentation are not very clear, and there seems to be a lack of helpful ...

Accordion feature that loads JSON data dynamically with AJAX

I am facing a challenge with my HTML structure and corresponding CSS styling. The HTML code includes an accordion container with multiple sections that can be expanded or collapsed. <div class="accordion-container"> <ul class="accordion"> ...

Elegant CSS background image fade effect

Having a small JS script that functions properly, but encountering an issue when quickly hovering over buttons causing the smooth transition effect to not work as desired. This abrupt change in image is quite unappealing. Any help would be greatly appreci ...

Send the data from the table to the controller

As a beginner in programming, I am trying to send a table input value to the controller. I have attempted the following method: $("#btnsend").click(function () { $.ajax({ type: "POST", contentType: "application/json ; charset=utf-8", ...

Is three too much for the Javascript switch statement to handle?

I'm a beginner in Javascript and am working on a project to create a fun program involving astrological signs, planets, and houses to generate a story. I have included three switch statements within one function to accomplish this. I'm encounter ...

What is the process of integrating unique themes into a non-Wordpress website?

In the process of developing my website, I am using PHP7, HTML5, CSS3, JQuery, and JavaScript5 instead of WordPress. One feature that I want to incorporate is the ability for users to customize their theme beyond the default option. How can this be achie ...

Manipulate the text within a swf file using jQuery

Looking for a solution to target links inside a SWF file connected to XML without access to the .fla or .swf files. Is there a way to achieve this using jQuery or Javascript? Any help is appreciated. ...

Leveraging a third-party UI component within an AngularJS directive

Have you heard of the npm package called smooth-dnd? If not, here is a link to its GitHub repository: https://github.com/kutlugsahin/smooth-dnd#readme This package is compatible with React, Angular, and Vue.js. However, my current project is built using ...

How to access the parameter of a function within a promise in AngularJS

In my AngularJS service, I have a function called getServiceData: var DataService = (function () { function DataService($log, $http, config) { this.$log = $log; this.$http = $http; this.config = config; } DataService.prototype.getService ...

Exploring the world of Polymer's Paper Elements and Angular Material

I need assistance in deciphering these quotes from the Angular Material GitHub and official website: It should be noted that this project is still in its early pre-release stage. Angular Material serves as a reference implementation of Material Design whi ...

The ipcRenderer.on() function is not receiving the mainWindow.webContents.send() message

Within the electron main.js file, my goal is to send an event from a child Window to a mainWindow. My initial plan was to achieve this by triggering an event from the childWindow to the Main Process, and then having the Main Process send an event to the ma ...

issues with the functionality of bootstrap modal

I'm currently working on a project where I need to set up a modal popup using bootstrap. The website I'm working on is organized by departments, so the only part of the code that I have control over is the main body of the site. I have included t ...

Translation of Angular datepicker

I'm currently utilizing the Angular Bootstrap Datepicker in my multilanguage application, but I've encountered an issue with translation. The problem arises with translating the buttons. While I can easily translate "CLOSE" and "Reset", the "Tod ...

Using Jquery to loop through a function for every select box that is added dynamically

Encountering some challenges with jQuery while attempting to utilize the same function and iterate over select boxes that are dynamically generated with jQuery's clone() method. Here is a snippet of the content being cloned: <select name="expense ...

Is there a way to maintain formdata between components in Angular?

With only the tools of @Input, @Output, routing, and activatedRoute at my disposal, I set out to create a dynamic application. In this project, there are two crucial components: addbook and showbook. The addbook component features a form with a submit bu ...

Having trouble getting the OwlCarousel directive to function properly

I have successfully created elements in the DOM, but for some reason, the plugin is not rendering the template. I am unsure if the problem lies with the plugin itself failing or if the Angular directive is not functioning as it should. Can someone please h ...

What is the best way to design a reusable component that can accept inputs and be utilized multiple times?

I created a search list feature where users can select items to add to a list within my app. The list component also includes an input section for users to set prices for each item. Interestingly, when setting a price for one item, the input fields for a ...

Loading a local FBX file in Three.js without the need to upload it

When attempting to load files selected by users in an HTML input, I encountered a problem with the loader expecting a URL in Linux style. I have tried various methods such as using a blob as a URL object, providing raw data to the FBX loader, and even usin ...