Skip to content

Commit

Permalink
Make rest on destroy configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
jayseo5953 authored and joegaudet committed Mar 9, 2023
1 parent ecbc0ac commit fddf803
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion addon/components/form-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,12 @@ export default class FormForComponent extends Component {
@arg(bool)
resetOnRejectedConfirm = true;

/**
* If true, checks isDirty to reset on destroy
*/
@arg(bool)
resetIfDirtyOnly = true;

// --------------------------------------------------------------------------------
// Methods
//
Expand Down Expand Up @@ -1139,7 +1145,8 @@ export default class FormForComponent extends Component {
}

willDestroy() {
if (this.isDirty && this.resetOnDestroy) {
const dirtyChecked = !this.resetIfDirtyOnly || this.isDirty;
if (this.resetOnDestroy && dirtyChecked) {
this.doReset();
}

Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/form-for-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ module('Integration | Component | form for', function (hooks) {
assert.dom('[data-test-field-for]').hasClass('readonly');
});

test('it runs all lifecycle hoooks when reseting the form', async function (assert) {
test('it runs all lifecycle hooks when reseting the form', async function (assert) {
sinon.stub(window, 'confirm').returns(true);

this.model = { foo: 'bar' };
Expand Down

0 comments on commit fddf803

Please sign in to comment.