Angular.js programmatically setting a form field to dirty

后端 未结 11 2026
孤独总比滥情好
孤独总比滥情好 2020-12-02 10:57

I am programmatically updating some of the fields on my form with a value and I would like to set the field state to $dirty. Doing something like:

11条回答
  •  情深已故
    2020-12-02 11:31

    Since AngularJS 1.3.4 you can use $setDirty() on fields (source). For example, for each field with error and marked required you can do the following:

    angular.forEach($scope.form.$error.required, function(field) {
        field.$setDirty();
    });
    

提交回复
热议问题