take-survey Widget Submit Button

abhi56
Tera Contributor

#want to customize take survey widget submit button 7community.PNG#n portal#

#I am using the Clone version of 1)surveys and Assessmet  widget id=take_assessment 

which ultimately call "take-survey" widget i am using the cloned version of it also for my customization 

in my case i want to change the features of the submit button 

on clicking of the submit button user should get a alert 

and after submit it should redirect to a particular link ...I tried to identify the on click function for the submit button in the client script but it is not working....

 

 

maybe this is the function for the submit function

c.submitAjax = function(formdata) {
   
        // first stringify the formData
        var stringifiedFormData = JSON.stringify(formdata);
        // then encode the stringified form data to handle any special characters and pass this to processor
        // this will be decoded in processor
        var encodedFormData = encodeURIComponent(stringifiedFormData);
       
        $http({
            method: 'POST',
            url: '/sp_survey.do',
            data: encodedFormData,
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded; charset=utf-8'
            }
        })
        .success(successHandler);

        function successHandler(responseData) {
            if (responseData.success === true || responseData.success === 'true') {
                if (formdata.original_action == 'save' || formdata.original_action  == 'submit') {
                    $scope.server.get({
                        action: 'log_assessment',
                        assessmentDetails: {type : c.data.evaluation_method_display, action_name : formdata.original_action , table : 'asmt_assessment_instance' , id : c.data.instanceId , name : c.data.title}
                });
                }
                var conclusion = c.data.parameterizedMsgsMap.submitted_msg;
                c.data.conclusion = (c.data.conclusion && c.data.conclusion.length > 0) ? c.data.conclusion : conclusion;
                if (formdata.sysparm_action == 'submit' || formdata.updateSuccessMessage) {
                    if (formdata.sysparm_action == 'submit') {
                        if (c.data.refreshInterval && c.data.refreshInterval > 0) {
                            c.data.successMessage = c.data.conclusion;
                            $timeout(function() {
                                $window.location.reload();
                            }, c.data.refreshInterval * 1000);                      
                        } else if (c.data.redirect_url && c.data.redirect_url.length > 0)
                             window.location.href = c.data.redirect_url;    
                        else
                             c.data.successMessage = c.data.conclusion;
                    } else if (formdata.sysparm_action == 'save')
                        c.data.successMessage = c.data.parameterizedMsgsMap.saved_msg;
                    else if (formdata.sysparm_action == 'cancel')
                        c.data.successMessage = c.data.parameterizedMsgsMap.not_saved_msg;
                }
            } else {
                c.showInlineErrorMessage(i18n.getMessage("Something went wrong. Please try again later."));
                c.invalidSurvey = true;
            }

            c.data.showMessage = true;
        }
    };
7 REPLIES 7

coryreidmiller
Tera Contributor

I would like to know the solution to this as well.

Juhi Poddar
Kilo Patron

Hello @abhi56 

In surveys and Assessment  widget in the html and client script check this:

JuhiPoddar_0-1735058892484.png

This is responsible for the submit button functionality.

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar

Hi @Juhi Poddar  

abhi56_0-1735059538485.png

I tried to add an alert msg on click of submit it is not working,

am I doing anything wrong?

Thank you

Abhinandan Nayak

Hi @abhi56 

You can create a new  function showAlert() and call it on click of Submit button. The closeSurvey Function will be called once user confirms.

Updated script in HTML:

<button class="btn btn-default" ng-click="c.showAlert()">{{data.assessment.parameterizedMsgsMap.close_btn_msg}}</button>

Updated script in client script:

		c.showAlert = function() {
			if (confirm("Your message here") == true) {
				c.closeSurvey();
			}
		};
		c.closeSurvey = function() {
			iframePayload.action = 'close';
			$window.postMessage(iframePayload, window.location.origin);
		};

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps others find the solution more easily and supports the community!"

 

Thank You
Juhi Poddar