Last active
September 10, 2018 14:42
-
-
Save thirumurthy/acce792e203dbe28c575d4935550013f to your computer and use it in GitHub Desktop.
It is a example sails framework javascript file for ajax-form post
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data: { | |
// Form data | |
formData: { /* … */ }, | |
// For tracking client-side validation errors in our form. | |
// > Has property set to `true` for each invalid property in `formData`. | |
formErrors: { /* … */ }, | |
// Syncing / loading state | |
syncing: false, | |
// Server error state | |
cloudError: '', | |
// Success state when form has been submitted | |
cloudSuccess: false, | |
}, | |
// ╦ ╦╔═╗╔═╗╔═╗╦ ╦╔═╗╦ ╔═╗ | |
// ║ ║╠╣ ║╣ ║ ╚╦╝║ ║ ║╣ | |
// ╩═╝╩╚ ╚═╝╚═╝ ╩ ╚═╝╩═╝╚═╝ | |
beforeMount: function() { | |
// Attach any initial data from the server. | |
_.extend(this, SAILS_LOCALS); | |
}, | |
mounted: async function() { | |
//… | |
}, | |
// ╦╔╗╔╔╦╗╔═╗╦═╗╔═╗╔═╗╔╦╗╦╔═╗╔╗╔╔═╗ | |
// ║║║║ ║ ║╣ ╠╦╝╠═╣║ ║ ║║ ║║║║╚═╗ | |
// ╩╝╚╝ ╩ ╚═╝╩╚═╩ ╩╚═╝ ╩ ╩╚═╝╝╚╝╚═╝ | |
methods: { | |
submittedForm: async function(response) { | |
if(response.APIstatus=="200") { | |
// If email confirmation is enabled, show the success message. | |
this.cloudSuccess = true; | |
} | |
else { | |
// Error message will display in the | |
this.syncing = true; | |
} | |
}, | |
handleParsingForm: function() { | |
// Clear out any pre-existing error messages. | |
this.formErrors = {}; | |
var argins = this.formData; | |
/* Validate full name: | |
if(!argins.fullName) { | |
this.formErrors.fullName = true; | |
}*/ | |
// If there were any issues, they've already now been communicated to the user, | |
// so simply return undefined. (This signifies that the submission should be | |
// cancelled.) | |
if (Object.keys(this.formErrors).length > 0) { | |
return; | |
} | |
return argins; | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment