6

How to keep the default form 'ng-model'

 2 years ago
source link: https://www.codesd.com/item/how-to-keep-the-default-form-ng-model.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to keep the default form 'ng-model'

advertisements

I have a input field say name. i have added a ng-model in it with default value of 'Enter your Name'. but now the form submit button gets enabled. how to prevent the submit button enable from the default value?

here is my code :

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

app.controller('MainCtrl', function($scope) {

  $scope.field = {};

  $scope.field.name="Enter your Name"; //because of default value form enables.

});

HTML :

<form name="myForm">

      <input type="text" name="name" id="name" ng-model="field.name" required>

      <button type="submit" ng-disabled="myForm.$invalid" >Submit</button>

    </form>

Live Demo


Use a placeholder instead of name. It has the intended effect without the above consequence.

<input type="text" name="name" id="name" placeholder="Enter your name" ng-model="field.name" required>

Tags angularjs

Related Articles

How to report the default form action after jquery ajax arrives?

I have this form: <form class='setPricetInput' method='post' action='mos.php'> <label> <span class = 'boldFont'>Your Selling Price:</span> <input type='text' class='moneyFormat reqPrice' autocomplete='off' name='b2'> </lab

How to set the default form in vb.Net?

How do I set form number four as the default form that will run when I press on f5 in visual studio 2008. Because form 1 will always be the first to startRight-click on your project in solution explorer. Choose properties. Select the Application Tab.

How to keep the default column header context menu on devexpress?

I have added a right click popup menu on my grid content. This popup also shows when I right click the grid header, however, I want to keep the default column header popup menu. My right menu code is like this: protected override void RightClickMenu(

How to keep the previous form entry when the user attaches a file

I have a form and it has an attachment button, is it possible to keep the entries they entered when they hit the attach file button and it refreshes? The inputs are all dropdowns, i'm not exactly sure how I should start with this..You have to catch t

Kendo numerictextbox: how to keep the default value even when it has been deleted?

I have Kendo numeric textbox.. I just want to know how to show default value when the user deleted the value and click outside the numeric textbox the textbox displays null, how can I make to show again the default value when it was deleted and click

How to keep the default open material search view

I am using the https://github.com/MiguelCatalan/MaterialSearchView for Search view. I want to keep the search view opened when I go to the materialsearchactivity.. My current code is public class search extends AppCompatActivity { MaterialSearchView

How to keep the default page size of my site while resizing the browser

I have a problem that's bothering me for a long, long time. How can I keep default page size of my site while resizing browser. Let's just say page size is 1280x720, how can I keep that size when I resize the browser? Example>google.com This means th

Android: How to keep the default number always even if the user wants to delete it, and how to delete the default number when the user enters a value?

I have a simple EditText, which inputs only numbers. I want to show 0(zero) even if user presses backspace. Now zero is getting deleted. Moreover, I need to remove this default zero, when user starts entering values. How do i achieve it?You should us

How to change css for an item but keep the default values ​​for its children

I want to set a certain font-family for a div, but I want it's children to keep the default properties. Is this possible?You cannot, because if an inner element does not itself have any value set for a particular property, it will inevitably inherit

how to assign the default value in the form input field for the password?

I am trying to design a form in put field similar to the one in twitter i need to assign default value for the input fields, i did assign ,but for password the value displayed was in a password format, how to show the default value of the password as

Crm 2011 - How to define a default form based on the value of the attribute (without using Javascript)?

I have a little requirement that is making me crazy: We have 8 different forms for the Contact Entity. We also have a pick list with 8 options. The idea is that based on the option selected we could open that Contact record showing by default a parti

How to keep the COMBOBox drop-down list by selecting items

I have a Windows Form custom comboBox that I'm hosting in a dataGridView. I can't figure out how to keep the drop down list open while the user selects items. There is no closing event to hook off of. Does anyone know how this is accomplished? I woul

Django sets the default form values

I have a Model as follows class TankJournal(models.Model): user = models.ForeignKey(User) tank = models.ForeignKey(TankProfile) ts = models.IntegerField(max_length=15) title = models.CharField(max_length=50) body = models.TextField() I have a modelfo

How to reveal the default Safari download folder via Applescript?

I am new to AppleScript and would like to know how to reveal the default downloads folder in Safari through AppleScript. --- WHAT I HAVE ALREADY TRIED --- set filePath to do shell script "defaults read com.apple.Safari DownloadsPath" do shell sc

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK