Lua Scripting Resources

Important Update to Custom Scripting

SurveyGizmo's CustomScript Action now supports the LUA programming language.


Legacy Custom Scripting Language Deprecation Plans 

  1. New accounts (created after October 29, 2018) will only have the option to use Lua in scripts.
  2. As of October 29, 2018 Custom Scripting Actions will default to Lua as the scripting type in the Custom Scripting Action for accounts created before this date. You will be able to switch to the Legacy Custom Scripting; though we highly encourage using Lua.
  3. In the long term, Legacy Custom Scripting Actions will be switched to read-only. Read-only scripts will continue to function; you will just be prevented from editing. The exact date on this is to be determined; we will send notifications well ahead of time.


 Go to our Legacy Scripting Documentation.

While SurveyGizmo is one of the most flexible survey tools around, we get requests for customizations that are not available out of the box. This is where JavaScript and Custom Scripting can save the day. If you have scripting chops you can use the JavaScript action or the Custom Scripting action to achieve the survey of your dreams.


[article("bodfy")]

The image selection question does not allow you to have an N/A Exclusive option. This tutorial will walk you through adding an exclusive option where no other images can be selected if the N/A option is selected. 

See the script in action in an example survey!

OR

Add a survey with this script and setup to your account.

The Script

After setting up your multi select image question with one image designated to be your "N/A" option click Action, select JavaScript, give it a name then click Save Action and Edit. Copy and paste the code below into the action:

jQuery(function($) {
    $(document).ready(function() {
        $(".sg-imageselect-item").click(function() {

            var find = 'N/A'; ///This must be changed in accordance with the title of the image you want to be exclusive
            var cur_clicked = $(this).find("img").attr("title");
            var parent = $(this).parents('.sg-question-options');

            if ( cur_clicked.indexOf(find)!=-1 ) { // if they click 'None of these'

                // add class to hook the unique none of these button
                $(this).addClass("sg-none-of-these");

                // then uncheck and remove classes on all
                parent.find(".sg-imageselect-item").not($(".sg-none-of-these")).each(function() {

                    $(this).find("input").attr("checked", false);
                    //$(this).find("input").attr("disabled", "disabled");
                    $(this).removeClass("sg-image-selected");

                });


                $(this).addClass("sg-image-selected");
                $(this).find("input").attr("checked", true);
            }else {
                // Item which isn't 'None of these' was clicked
                // and
                // If 'None of these' is ticked then untick it and uncheck it
                parent.find("input[title='"+find+"']").attr("checked", false);
                parent.find("input[title='"+find+"']").parent().parent().parent().parent().removeClass("sg-image-selected");
                parent.find(".sg-none-of-these input").attr("checked", false);
                parent.find(".sg-none-of-these").removeClass("sg-image-selected");
            }        
        });

    }); // end ready

}); // end JQuery

After pasting the JavaScript, change the text in yellow to match the reporting value of your image file.