Skip to content

Instantly share code, notes, and snippets.

@travist
Last active July 12, 2023 14:56
Show Gist options
  • Save travist/fc10ab3ebdfc5e2e8b9929efb2e6ef18 to your computer and use it in GitHub Desktop.
Save travist/fc10ab3ebdfc5e2e8b9929efb2e6ef18 to your computer and use it in GitHub Desktop.
Enable Save As Draft in Angular.
import debounce from 'lodash/debounce';
@Component({
...
})
export class MyController {
public submission = {};
ngAfterViewInit() {
var currentSubmission = localStorage.getItem('currentSubmission-' + this.route.params.formId);
if (currentSubmission) {
this.submission = JSON.parse(currentSubmission);
this.cdr.detectChanges();
}
}
onChange(submission) {
localStorage.setItem('currentSubmission-' + submission.form, JSON.stringify(submission));
}
}
<formio [src]="formURL" (change)="onChange($event)" [submission]="submission" [renderOptions]="{
saveDraft: true,
saveDraftThrottle: 10000
}"></formio>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment