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

  • SEARCH
  • Home
  • 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 9243545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T08:49:55+00:00 2026-06-18T08:49:55+00:00

I have a simple form like so: <form name=add-form data-ng-submit=addToDo()> <label for=todo-name>Add a new

  • 0

I have a simple form like so:

<form name="add-form" data-ng-submit="addToDo()">
    <label for="todo-name">Add a new item:</label>
    <input type="text" data-ng-model="toDoName" id="todo-name" name="todo-name" required>
    <button type="submit">Add</button>
</form>

with my controller as follows:

$scope.addToDo = function() {
    if ($scope.toDoName !== "") {
        $scope.toDos.push(createToDo($scope.toDoName));
    }
}

what I’d like to do is clear the text input after submission so I simply clear the model value:

$scope.addToDo = function() {
    if ($scope.toDoName !== "") {
        $scope.toDos.push(createToDo($scope.toDoName));
        $scope.toDoName = "";
    }
}

Except now, because the form input is ‘required’ I get a red border around the form input. This is the correct behaviour, but not what I want in this scenario… so instead I’d like to clear the input and then blur the input element. Which leads me to:

$scope.addToDo = function() {
    if ($scope.toDoName !== "") {
        $scope.toDos.push(createToDo($scope.toDoName));
        $scope.toDoName = "";
        $window.document.getElementById('todo-name').blur();
    }
}

Now, I know that modifying the DOM from the controller like this is frowned upon in the Angular documentation – but is there a more Angular way of doing this?

  • 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-18T08:49:56+00:00Added an answer on June 18, 2026 at 8:49 am

    When you give a name to your form it automatically gets added to the $scope.

    So if you change your form name to “addForm” (’cause I don’t think add-from is a valid name for angular, not sure why), you’ll have a reference to $scope.addForm.

    If you use angular 1.1.1 or above, you’ll have a $setPristine() method on the $scope.addForm. which should recursively take care of resetting your form. or if you don’t want to use the 1.1.x versions, you can look at the source and emulate it.

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

Sidebar

Related Questions

I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
I have a simple form like this : <form method=post name=change_pass id=change_pass action=change_pass2.php> <input
I have a very simple contact form with fields like this: <label> First Name<em>*</em>
I have a simple form and would like to add a custom jQuery validation
I have a simple html form that is structured something like this: <form name=test
I have a simple ExtJS form, but I would like to add additional attributes
I have a normal form using simpleform. Now I'd like to add an input
I have a form to upload image like below <form name=sample enctype=multipart/form-data action=index.php method=post
I have simple form like this which accepts only two values string action and
I have a simple form that looks like this: <%= simple_form_for @study,:url => studies_path,

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.