Skip to content

Commit

Permalink
Add optional reset of form on confirmSubmit false
Browse files Browse the repository at this point in the history
  • Loading branch information
joegaudet committed May 13, 2022
1 parent 5cee4c4 commit 1e00235
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions addon/components/form-for.js
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,17 @@ export default class FormForComponent extends Component {
@arg(bool)
resetOnDestroy = true;

/**
* If true, resets the form when confirmation is not provided
*
* @property resetOnRejectedConfirm
* @type Boolean
* @default true
* @public
*/
@arg(bool)
resetOnRejectedConfirm = true;

// --------------------------------------------------------------------------------
// Methods
//
Expand Down Expand Up @@ -769,12 +780,11 @@ export default class FormForComponent extends Component {
const model = this.model;
const isSaving = model?.isSaving;

let shouldSubmit = !isSaving ? (await this.willSubmit(model)) : false;
shouldSubmit &&= (await this.confirmSubmit(model));
shouldSubmit ||= this.allowSubmitQueue;

// Guard if the model is saving
if (shouldSubmit) {
const willSubmit = !isSaving ? (await this.willSubmit(model)) : false;
const confirmSubmit = await this.confirmSubmit(model);

if (willSubmit && confirmSubmit || this.allowSubmitQueue) {
this._markSubmitting();

const onSubmit =
Expand Down Expand Up @@ -816,6 +826,10 @@ export default class FormForComponent extends Component {
this.didNotSubmit(model);
this.notifyError(this.didNotSubmitMessage);

if(!confirmSubmit && this.resetOnRejectedConfirm) {
await this.doReset();
}

return Promise.resolve(true);
}
}
Expand Down

0 comments on commit 1e00235

Please sign in to comment.