Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8959367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:25:12+00:00 2026-06-15T15:25:12+00:00

I am having an issue with AngularJS validation on a form/model that is loaded

  • 0

I am having an issue with AngularJS validation on a form/model that is loaded immediately by a controller. The form loads in a partially incorrect validation state, and the only way to get back to a correct validation state is to enter an actual invalid state. The other workaround is to set the model for the form with a 1ms delay. I have created a jsFiddle the describes this functionality here: http://jsfiddle.net/YAuxm/4/

Just for more clarification, on a property that is marked as required that is initialized with a valid value, the form and the input are both correctly marked as valid, however the wrapping div is marked as invalid. Modifying the value has no effect until the value is actually invalid (i.e. empty). Once the field is properly invalidated, then all subsequent changes will be properly validated until the route is changed, in which case the behavior is back to what I have described here.

Here is an abbreviated version of the example posted on jsFiddle:

<div ng-app="Test">    
    <script type="text/ng-template" id="Templ">        
        <ul style="width:20%; float:left;">
            <li ng-repeat="item in Items">
                <a href="#/edit/{{item.Id}}">Edit {{item.Name}}</a>
            </li>
        </ul>    

        <form name="editor" ng-show="CurrentItem">           
            <!-- this evaluates to true on initial load even when the value is valid -->                
            <div ng-class="{error: editor.ItemName.$invalid}"> 
                <input type="text" name="ItemName" ng-model="CurrentItem.Name" required />               
        </form>        
    </script>   

    <div ng-view></div>                    
</div>​

<script type='text/javascript'>

var items = [{Id: 0, Name: 'Item 1', SomeNumber: 100},
             {Id: 1, Name: 'Item 2', SomeNumber: 200},
             {Id: 2, Name: 'Item 3', SomeNumber: 300}];


angular.module('Test', []).
    config(function($routeProvider) { $routeProvider.
        when('/edit/:itemIndex', { controller: TestCtrl, templateUrl: 'Templ' }).
        otherwise({ redirectTo: '/edit/0' });
    });

function TestCtrl($scope, $location, $routeParams) {
    $scope.Items = items;    
    $scope.CurrentItem = $scope.Items[$routeParams.itemIndex];                       
}
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:25:14+00:00Added an answer on June 15, 2026 at 3:25 pm

    Your example works in AngularJS 1.0.2 JSFiddle here, but it doesn’t in 1.0.3. We are able to get the value of editor.ItemName.$invalid, but apparently the ngClass directive might be broken. Check this issue on github:

    • https://github.com/angular/angular.js/issues/1637

    The quick fix would be to be add a CSS rule to style the .control-group when the form is invalid. For example:

    form.ng-invalid-required .control-group{background-color: red; color:#fff}
    

    JSFiddle Angular 1.0.3

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue with angularjs validation, see http://jsfiddle.net/NR55T/1/ . Basically there is a
I having issue that content assistant / intellisense is working in methods such as
Having an issue here that I have tried everything I can think of but
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
I'm having an issue with custom directives that's driving me crazy. I'm trying to
I'm having issue with Action Listener of a JTable that being updated according the
We have a device that support SAE J1939 interface and having issue with finding
I'm having an issue with changing the URL of the page after a form
I'm having issue assigning regex value to a string. Issue that I have is
I'm trying to save data with field that has validation isUnique rule but having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.