Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Form Builder action 'save' doesn't seem to work or trigger onSave #1058

Closed
harpsicord86 opened this issue Mar 30, 2020 · 7 comments · Fixed by #1112
Closed

Form Builder action 'save' doesn't seem to work or trigger onSave #1058

harpsicord86 opened this issue Mar 30, 2020 · 7 comments · Fixed by #1112
Labels

Comments

@harpsicord86
Copy link

Description:

Following the documentation at https://formbuilder.online/docs/formBuilder/actions/save/ this function does not seem to do anything. It also does not seem to trigger onSave when used. Could you provide some guidance on this please?

Environment Details:

  • formBuilder Version: 3.4.2
  • Browser: Google Chrome
  • OS: Win 10

Expected Behavior

Running formBuilder.actions.save() would trigger onSave in options.

Actual Behavior

Running formBuilder.actions.save() actually does nothing.

Steps to Reproduce

add onSave as part of options and add an alert or console.log to function. Run formBuilder.actions.save() after form builder is initialised

@ahmedsu
Copy link

ahmedsu commented Mar 30, 2020

I have the same problem :S

@ahmedsu
Copy link

ahmedsu commented Mar 30, 2020

@harpsicord86 Hey Steve! If your goal is to show form render, here is an example how you can do it:

<div id="fb-editor" ref={this.fb} />
          <div id="fb-rendered-form" ref={this.fbPreview}>
             <form action="#"></form>
            <button class="btn btn-default edit-form">Edit</button>
        </div>
       <button onClick={this.saveSurvey}>
           Save survey
     </button>

You should use your own external save button.

  componentDidMount() {

   this.surveyCreator = $(this.fb.current).formBuilder({formData});
  }


  saveSurvey = () => {
    console.log("==== SAVE SURVEY ====");
    console.log(this.fb);
    console.log(this.surveyCreator);

    $(this.fb.current).toggle();
    $(this.fbPreview.current).toggle();
    console.log($('form', this.fbPreview.current));
    $('form', $(this.fbPreview.current)).formRender({
        formData: this.surveyCreator.formData
      });

  }

@harpsicord86
Copy link
Author

Hi @ahmedsu thanks for the tip! But all I've been trying to do is to capture saving the form at build if the user closes the web page down. I thought there was an elegant way of doing it but there ain't... I've used the getData() action to get the json of the form to save through ajax. Honestly, I thought save() would have called onSave() :-(

@GrumpyCrouton
Copy link

GrumpyCrouton commented May 15, 2020

@harpsicord86 You could use getData() and the beforeunload bind.

$(window).bind('beforeunload', function(){
	//call getData() and store it
});

@haiyangdeperci
Copy link

Could you tell me how to trigger onSave? I am trying to mimic the save action button behaviour by calling formBuilder.actions.save(); but apparently the original button triggers onSave separately:

{
  type: "button",
  id: "save",
  className: "btn btn-primary save-template",
  events: {
    click: function(e) {
      t.save(),
      m.a.opts.onSave(e, t.data.formData)
    }
  }
}

Is there any way to replicate it?

@kevinchappell
Copy link
Owner

onSave will now be called when save is called from the api.

github-actions bot pushed a commit that referenced this issue Aug 23, 2020
## [3.4.5](v3.4.4...v3.4.5) (2020-08-23)

### Bug Fixes

* onSave not called when save called from the api ([d607b02](d607b02)), closes [#1058](#1058)
@kevinchappell
Copy link
Owner

🎉 This issue has been resolved in version 3.4.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants