The form code allows you to run and execute some custom javascript code while the survey is starting and running.
Your custom code must extends the NGSFormCode object to be executed.
/* 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*/classCustomFormCodeextendsNGSFormCode { /* 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. */onSaveProgress(ngsRespondent) {}/* Trigger once the respondent answers have been saved on the server. */onSubmit(ngsRespondent) {// Respondent detailsconsole.log(ngsRespondent.respondent);// Respondent answersconsole.log(ngsRespondent.answers);// security items data attributes valuesconsole.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);}}
The NGSForm base class provide following properties that you can reuse in your derived class.
classNGSFormCode {// Current survey survey;// Form context helper class formContext;// Current respondent answers respondentAnswers;// Current respondent respondent;// Current running language code language;// Current data attribute values from security items dataAttributesValues; }
FormContext provides following properties that you can use from your NGSFormCode derived class through the formContext property.
exportclassFormContext {// Current respondent answersprivate respondentAnswers$:Observable<RespondentAnswer[]>,// Current security items data attributesprivate dataAttributesValues$:Observable<RespondentAnswer[]>,// Current respondent languageprivate language$:Observable<Language>,// Angular HTTP clientprivate httpClient:HttpClient,}