Skip to content

Commit d19271d

Browse files
committed
Optimize class applications for forms
1 parent c80b953 commit d19271d

2 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/core/scope/scope.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,6 +1169,7 @@ export class Scope {
11691169
}
11701170
}
11711171

1172+
/* @ignore */
11721173
$flushQueue() {
11731174
while ($postUpdateQueue.length) {
11741175
$postUpdateQueue.shift()();

src/directive/form/form.js

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isUndefined,
99
isObjectEmpty,
1010
isProxy,
11+
hasAnimate,
1112
} from "../../shared/utils.js";
1213
import {
1314
PRISTINE_CLASS,
@@ -264,8 +265,14 @@ export class FormController {
264265
* state (ng-dirty class). This method will also propagate to parent forms.
265266
*/
266267
$setDirty() {
267-
this.$$animate.removeClass(this.$$element, PRISTINE_CLASS);
268-
this.$$animate.addClass(this.$$element, DIRTY_CLASS);
268+
if (hasAnimate(this.$$element)) {
269+
this.$$animate.removeClass(this.$$element, PRISTINE_CLASS);
270+
this.$$animate.addClass(this.$$element, DIRTY_CLASS);
271+
} else {
272+
// Fallback for non-animated environments
273+
this.$$element.classList.remove(PRISTINE_CLASS);
274+
this.$$element.classList.add(DIRTY_CLASS);
275+
}
269276
this.$dirty = true;
270277
this.$pristine = false;
271278
this.$$parentForm.$setDirty();
@@ -284,11 +291,18 @@ export class FormController {
284291
* saving or resetting it.
285292
*/
286293
$setPristine() {
287-
this.$$animate.setClass(
288-
this.$$element,
289-
PRISTINE_CLASS,
290-
`${DIRTY_CLASS} ${SUBMITTED_CLASS}`,
291-
);
294+
if (hasAnimate(this.$$element)) {
295+
this.$$animate.setClass(
296+
this.$$element,
297+
PRISTINE_CLASS,
298+
`${DIRTY_CLASS} ${SUBMITTED_CLASS}`,
299+
);
300+
} else {
301+
// Fallback for non-animated environments
302+
this.$$element.classList.remove(DIRTY_CLASS, SUBMITTED_CLASS);
303+
this.$$element.classList.add(PRISTINE_CLASS);
304+
}
305+
292306
this.$dirty = false;
293307
this.$pristine = true;
294308
this.$submitted = false;
@@ -326,7 +340,11 @@ export class FormController {
326340
}
327341

328342
$$setSubmitted() {
329-
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
343+
if (hasAnimate(this.$$element)) {
344+
this.$$animate.addClass(this.$$element, SUBMITTED_CLASS);
345+
} else {
346+
this.$$element.classList.add(SUBMITTED_CLASS);
347+
}
330348
this.$submitted = true;
331349
this.$$controls.forEach((control) => {
332350
if (control.$$setSubmitted) {

0 commit comments

Comments
 (0)