formio.js icon indicating copy to clipboard operation
formio.js copied to clipboard

SaveDraft is not working for me

Open DonAmit197 opened this issue 3 years ago • 8 comments

My requirement is when I click the Save button the user input will save into a draft and as in Form IO under "Use" behavior user will be redirected to a page to view the draft mode. Again on clicking the Edit button there, the user can start editing the rest of the fields.

I tried to integrate following the documentation, but not working for me:

Formio.createForm(document.querySelector("#<%=tools.getParamValue("formIOID") %>"), <%= jsonText %>, {saveDraft: true}).then(function(form){
 getNextPageResponse(form);
 saveSubmit(form);
       
});

I am also instantiating the method to window.location inside thesubmitevent, still no luck.

Any help is highly appreciated.

DonAmit197 avatar Oct 31 '22 05:10 DonAmit197

Try setting the submission.state property to "draft" before submit. form.submission.state = 'draft';

edwinanciani avatar Oct 31 '22 21:10 edwinanciani

Thanks, @edwinanciani for your comment. I'll look into it.

DonAmit197 avatar Oct 31 '22 21:10 DonAmit197

Hi,

I'm also having no luck with getting this feature working. We host an on premise enterprise environment (Portal version Application: 7.0.40, Renderer: 4.11.3)

I follow the documentation here: https://formio.github.io/formio.js/app/examples/savedraft.html To clarify: I'm trying to implement this for "Anonymous" user And created this form: https://codepen.io/duongph/pen/VwYZvaV I verified the Formio.setUser function worked: image

When the "Save as draft" button is clicked, the draft submission is successfully submitted, however there seems to be several issues:

  • Spin icon does not stop on the Save as Draft button
  • The "owner" is not set on the submission
  • When returning to the form (refresh or open a new browser tab) the data is not restored. If I check console the error shows "Cannot restore draft because there is no formio instance." image

phucduong86 avatar Nov 22 '22 21:11 phucduong86

I modified the script and it worked for me. Form Io has a method if(component.component.key ==="") with which we can trigger any component. Through it, I found the Save button component and initiated my custom function to save the form data and it's working perfectly for me.

DonAmit197 avatar Nov 23 '22 03:11 DonAmit197

@phucduong86 have you actually solved this issue? I have the same behavior.

apasashkov avatar Mar 20 '23 14:03 apasashkov

hi @DonAmit197 can you send a piece of code which has if(component.component.key ==="") i want to know the way of using?

vineelaampili avatar Oct 10 '23 10:10 vineelaampili

You can only use what you are after in form.everyComponent method where component is a parameter.

DonAmit197 avatar Oct 10 '23 12:10 DonAmit197

@phucduong86 have you actually solved this issue? I have the same behavior.

Hi, unfortunately no we are shelving this work item for now.

phucduong86 avatar Oct 10 '23 12:10 phucduong86

@DonAmit197 it appears that you have resolved this behavior, if not please let us know. @phucduong86 Save as Draft will not work with Anonymous users, please find more details at: https://help.form.io/faq/tutorials-and-workflows/save-as-draft

Sidiro23 avatar Mar 20 '24 13:03 Sidiro23