Form Code
👨💻️ What is form code ?
/*
Sample that shows how to post respondent
answers to a third party REST API.
The Form code can also be used to insert third party
API codes to your form page using the onInit or onLoaded events
*/
class CustomFormCode extends NGSFormCode {
/* Form has been loaded */
onInit() {}
/* A security item requires authentication will be called
when a survey requires authentication from an security item
*/
onAuthenticate(securityItem) {}
/* A security item requires authentication will be called
a security item has been succesfully authenticated.
Returning a string from this method will block the
access the survey with the message defined by the
returning string.
*/
onAuthenticated(securityItem, securityItemAuthorization) {}
/* Form has been authorized by all security items and loaded
with questions of its first visible page */
onLoaded() {}
/* Trigger when a new page is being loaded a null value for the page
indicates that the end thank you page is being loaded
*/
onPageLoad(page) {}
/* Trigger once the respondent session answers have been saved on the server.
action defines the action that triggered the save progress it can be any of following values
None = 0, Button = 1, PageChange = 2, QuestionChange = 3, Email = 4, Auto = 5
*/
onSaveProgress(ngsRespondent, action) {}
/* Trigger once the respondent answers have been saved on the server. */
onSubmit(ngsRespondent) {
// Respondent details
console.log(ngsRespondent.respondent);
// Respondent answers
console.log(ngsRespondent.answers);
// security items data attributes values
console.log(ngsRespondent.dataAttributes);
this.formContext.httpClient.post('http://www.yourrestsite.com/yourapi/saveanswers',
ngsRespondent.answers, {}).subscribe();
}
/* Trigger once the respondent answers have been updated on the server. */
onUpdate(ngsRespondent) {console.log('update', ngsRespondent);}
}Last updated
Was this helpful?