What causes the selection of the menu item $invalid to always return as true?

I have an HTML form with a select menu:

<form name="form">
     <select name="gender" ng-model="model" ng-required="true"
      ng-model-options="{ updateOn: 'mousedown blur'}">
          <option value="" disabled>--Select--</option> 
          <option value="Male">Male</option> 
          <option value="Female">Female</option> 
     </select>
</form>

<form-error element="gender"><p>Please select Gender</p></form-error>

I am implementing this using angularJS javascript in a custom directive

.directive('formError', function() {
    'use strict';
     return {
        require: ['^form'],
        restrict: 'E',
        templateUrl: '/partials/form-fields/validations/error.html',
        scope: {},
        transclude: true,
        replace: true,
        link: function($scope, $element, $attr, form) {
            var element = $attr.element;

            $scope.form = form[0];

            $scope.$watch('form.' + element + '.$viewValue', function(newVal, oldVal){
            $scope.$dirty = $scope.form[element].$dirty;
            $scope.$valid = $scope.form[element].$valid;
            $scope.$invalid = $scope.form[element].$invalid;
            $scope.$value = newVal;

            console.log($scope.form.gender.$invalid);
         }, true);

         $scope.$watch('form.$submitted', function(newVal, oldVal){
             $scope.$submitted = newVal;
         }, true);
    }
});

The directive above relates to the following HTML snippet

 <div class="input__error"
      ng-if="($dirty && $invalid && $value !== '') || ($submitted && $invalid)"
      ng-transclude></div>

When typing in any text input field, the $invalid variable switches from true to false as expected. However, when selecting "Male" from the dropdown menu, it still remains true for $invalid. Only when selecting "Female", $invalid becomes false.

Essentially, I want the error message to disappear when "Male" is selected.

Any insight on why this might be happening?

Answer №1

ng-model-options="{ updateOn: 'mousedown blur'}

The select menu validation problem was resolved once I removed this particular code snippet.

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

The error message in the lang.js file on line 21 says: "There is a Syntax

https://i.sstatic.net/mLrvW.png Here's my package.json file: "ng2-file-upload": "1.0.3", "ng2-translate": "2.5.0", "angular2-cookie": "1.2.3", "angular2-google-maps": "0.15.0", "key-codes": "0.0.1", "rxjs": "5.0.0-beta.12" "@angular/common": "2.0.0" ...

Make sure to adjust the original router URL when the application is being run within iframe or object

Currently, I am embedding Vue apps within object tags or iframes of a master Vue app container. Initially, I set up a file server that serves the container or the requested sub-app to render inside a div. Below, I will show the necessary routing of my Nod ...

Adding Firebase Authentication to my AngularJS website

I am currently creating a school website using AngularJS. My goal is to incorporate account functionality through firebase authentication. However, I have limited experience with Javascript and find working with AngularJS and implementing firebase to be ...

angular material theme malfunctioning

Within the configuration block, I have set up the following: .config(['$urlRouterProvider', '$stateProvider', '$locationProvider', '$mdThemingProvider', function ($urlRouterProvider, $stateProvider, $locationProvid ...

AngularJS session timeout refers to the period of inactivity before

Would it be possible to handle user sessions with Angularjs? For example: Setting session timeout for idle systems. Displaying alerts (popup with message asking if the user wants to continue - yes or no) when the session is about to expire, with the optio ...

Finding the difference or sum within an array to identify the two numbers that produce a new array

In order to clarify, I am looking for a method to identify the two smallest numbers in a sorted array that will result in a specific number when subtracted. The process can be broken down into the following steps: Iterate through the array and designate ...

Inverted Scrolling Problem in Firefox

I am facing an issue with a script that inverts mouse movement for horizontal scrolling. It works fine in most browsers except Firefox. I could use some advice on how to troubleshoot this problem! $("body").mousewheel(function(event, delta) { ...

Incorporating a personalized image to create custom icons on the Material UI bottom navigation bar

Is it possible to replace the default icon with a custom image in material ui's BottomNavigation component? I'm curious if Material UI supports this feature. If you'd like to take a closer look, here is the link to the codesandbox. ...

What could be the reason for the component failing to update even after modifying the object's properties?

I have come across some related threads on Stack Overflow, but they only briefly mention using the spread operator. But why should we use it? In the code below, I am trying to update the firstName property of the user object, which is a state, when clicki ...

Embedding a function within a directive without using an isolated scope

Am I approaching this correctly? I am utilizing the ui-select directive, but it seems like it does not support the HTML required directive. Therefore, I created my own directive called ui-select-required. The challenge lies in using isolate scope because u ...

When making an ajax call, I passed the data "itemShape" but on the URL page, an error appeared stating "Undefined index: itemShape"

Hello, I have been using an Ajax function to send data with the key itemShape. However, when I directly access the URL page or service page, it displays the following error: Notice: Undefined index: itemShape in C:\wamp64\www\inventory_so ...

Unable to modify the bar's color using the .css document

Below is the JavaScript code being used: var marginEducation = {top: 20, right: 30, bottom: 40, left: 300}, widthEducation = 1000, heightEducation = 460; const svgEducation = d3.select("#Education") .append("svg") .attr("w ...

Determine the frequency of a specific key in an array of objects

original array: ................ [ { from: {_id: "60dd7c7950d9e01088e438e0"} }, { from: {_id: "60dd7c7950d9e01088e438e0"} }, { from: {_id: "60dd7e19e6b26621247a35cd"} } ] A new array is created to count the instances of each ...

Utilize the same variable within a React functional component across multiple components

Within a React functional component, I am utilizing the following constant: const superHeroPowers = [ { name: 'Superman', status: superManPowerList }, { name: 'Batman', status: batmanPowerList }, { name: 'Wonder Woman&a ...

"Limitation observed - function operates only on first attempt

I have been working on a map project that involves pulling information from Google about various locations using the library available at https://github.com/peledies/google-places In order to troubleshoot and identify the issue with the code related to ma ...

Using AngularJS to inject a service into a static property of a standard class

For my current project, I am combining TypeScript and AngularJS. One of the challenges I'm facing is how to instantiate a static member of a public class (not controller, just a normal class) with a service object. When it comes to controllers, utiliz ...

Instructions for creating a po file from a js file using poedit

Utilizing the Gettext.js library for localizing content created from a JS file has been my approach. The current challenge lies in the manual creation and writing of each po file. It is known that php files can be scanned for gettext strings using PoEdit ...

Utilizing conditional statements within the array.forEach method to select specific sub-objects within an array of objects

Need help troubleshooting an if statement inside a function that is called by a forEach array loop. My array contains objects, with each object structured like this: arrofobj = [ {"thing_id":"1a", "val": 1, "Type": "Switch","ValType":{"0":"Open","1":" ...

AngularJS view displays previous data momentarily before transitioning to the updated data upon switching views

My angularJS / nodejs / express app consists of a single page. Upon the initial load, it retrieves data from the database using an API and presents it in a table within the 'home' route. Every 5 minutes, the app updates the data by making another ...

How to redirect in Next.js from uppercase to lowercase url

I'm trying to redirect visitors from /Contact to /contact. However, following the instructions in the documentation results in an endless loop of redirects. This is my attempted solution: // next.config.js async redirects() { return [ { ...