Angular.js programmatically setting a form field to dirty

后端 未结 11 2047
孤独总比滥情好
孤独总比滥情好 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 11:24

    you will have to manually set $dirty to true and $pristine to false for the field. If you want the classes to appear on your input, then you will have to manually add ng-dirty and remove ng-pristine classes from the element. You can use $setDirty() on the form level to do all of this on the form itself, but not the form inputs, form inputs do not currently have $setDirty() as you mentioned.

    This answer may change in the future as they should add $setDirty() to inputs, seems logical.

提交回复
热议问题