Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular js set form to dirty programmatically

Tags:

angularjs

my check boxes run a function with operates several tasks to manipulate the model programmatically and this seems to not allow the form to become dirty.

on the basis my form is named "testForm" how would I include a reference in my existing function to set the form to be dirty when that checkbox calls it on click?

do I need to reference the forms name or is it a case of setting the model to be dirty such as

$scope.$dirty = true;
like image 524
user3779703 Avatar asked Mar 23 '16 09:03

user3779703


People also ask

How do you set a form group to dirty?

You should use the markAsDirty method, like this: control. markAsDirty(); This will also mark all direct ancestors as dirty to maintain the model.

What is setPristine ()?

$setPristine();Sets the form to its pristine state. This method sets the form's $pristine state to true, the $dirty state to false, removes the ng-dirty class and adds the ng-pristine class.

What is form dirty in angular?

When the user changes the value in the watched field, the control is marked as "dirty" When the user blurs the form control element, the control is marked as "touched"

What is Ng-dirty in AngularJS?

ng-dirty: The ng-dirty class tells that the form has been made dirty (modified ) by the user. It returns true if the user has modified the form. Return type: Return Boolean True if the form/input field is modified by the user else it returns False.


1 Answers

$form.$setDirty();     
$form.email.$dirty = true;

Here, $form = form.
email = field name.

like image 86
Ved Avatar answered Nov 15 '22 22:11

Ved