Sails: Returning created Object to submitted function of Ajax Form

Created on 12 Oct 2018  路  6Comments  路  Source: balderdashy/sails

Sails version: 1.0.2
Node version: 8.10.0
NPM version: 6.4.1
DB adapter name: sails-mongo
DB adapter version: sails-mongo
Operating system: Mac OS



Hello,
I want to get an object from an action, which is called by an ajax form component.

Steps to reproduce.

  1. create a ajax form where you passing values for a model (eg. title and description for a post)

  2. After handling the submitting form let pass the data to a action

  3. In the action you will safe the given data to the MongoDB and fetch that created data with .fetch()

  4. You pass the fetched data to exits.success(fetchedData)

  5. Try to get the data in the submittedForm function in the xxxx.page.js

I am not able to get the data. I logged the ajax-form.components.js. In line 398, we emit the result (the result should have our data, in my case it is the fact) but after that, the result is gone.
Maybe I understand it wrong, obviously I do things wrong.

If you need more info, let me know.

does this answer your question?

Most helpful comment

To get data back from the back end using an ajax form, you need to include a 'submitted' function. In your html:

<ajax-form action="nameOfAction" @submitted="submittedAjaxForm" ... >

This function runs only if the action returns a success response. In the page script (front-end javascript file that includes a .page in the file name), you will define this function and what you want to do with the data:

submittedAjaxForm: async function (responseData) { console.log(responseData); }

All 6 comments

Hi @bleakhead! It looks like you missed a step or two when you created your issue. Please edit your comment (use the pencil icon at the top-right corner of the comment box) and fix the following:

  • Verify "I am experiencing a concrete technical issue (aka a bug) with Sails (ideas and feature proposals should follow the guide for proposing features and enhancements (http://bit.ly/sails-feature-guide), which involves making a pull request). If you're not 100% certain whether it's a bug or not, that's okay--you may continue. The worst that can happen is that the issue will be closed and we'll point you in the right direction."
  • Verify "I am not asking a question about how to use Sails or about whether or not Sails has a certain feature (please refer to the documentation(http://sailsjs.com), or post on http://stackoverflow.com, our Google Group (http://bit.ly/sails-google-group) or our live chat (https://gitter.im/balderdashy/sails)."
  • Verify "I have already searched for related issues, and found none open (if you found a related _closed_ issue, please link to it in your post)."
  • Verify "My issue title is concise, on-topic and polite ("jst.js being removed from layout.ejs on lift" is good; "templates dont work" or "why is sails dumb" are not so good)."
  • Verify "I have tried all the following (if relevant) and my issue remains:"
  • Verify "I can provide steps to reproduce this issue that others can follow."

As soon as those items are rectified, post a new comment (e.g. “Ok, fixed!”) below and we'll take a look. Thanks!

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

Ok, fixed!

Sorry to be a hassle, but it looks like your issue is still missing some required info. Please double-check your initial comment and try again.

*If you feel this message is in error, or you want to debate the merits of my existence (sniffle), please contact [email protected]

To get data back from the back end using an ajax form, you need to include a 'submitted' function. In your html:

<ajax-form action="nameOfAction" @submitted="submittedAjaxForm" ... >

This function runs only if the action returns a success response. In the page script (front-end javascript file that includes a .page in the file name), you will define this function and what you want to do with the data:

submittedAjaxForm: async function (responseData) { console.log(responseData); }

Hi @Ghost I hope @streleck commit got you moving in the right direction. To tidy up the Sails issues we are closing issues that are older or resolved. Please feel free to create another issue if the need arises.

Was this page helpful?
0 / 5 - 0 ratings