Welcome, Guest
Username: Password: Remember me

TOPIC: Customization: Extending Boilerplate Question

Customization: Extending Boilerplate Question 3 years 1 month ago #58542

  • RickWyatt
  • RickWyatt's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 1
  • Karma: 0
I've been hired by another developer who has already done some LimeSurvey customization. Their client has a need to display various items - maybe show a video, maybe display a neutral face for a certain number of miliseconds, maybe flash a certain color a certain number of times. There will be no response to this question: instead the next x questions will be questions gauging response to what the participant has just seen.

The first part of this is easy - just use a boilerplate and have the boilerplate code be a call to a javascript function / page we set up. So basically we've only established a mechanism for a question type to call our javascript function, at which time our custom code can be in control of what is presented in the boilerplate section of the question. So our boilerplate would be something like:
<script type="text/javascript" src="customizedBoilerplate.js"></script>

And that javascript would be what flashes the color, shows the video, whatever.

The problem comes in how to let the person setting up the survey set values like what color and how many times to flash it, or how long to show a video. We could just have them type it in when copying the code, something like this:
<script type="text/javascript">
bpvar_color = "FF0000";
bpvar_numFlashes = 3
</script>
<script type="text/javascript" src="myscript.js"></script>

But our users aren't exactly coders. So our thought is to add new attributes to the boilerplate class. Right below where your code displays the "Advanced Attributes" link we would add a link called "Special Boilerplates." If that link is selected, it will bring up a dropdown of the possible boilerplates - like VIDEO, COLOR TEST, or NEUTRAL FACE. Then we'll have all the possible attributes that can be set, like number of flashes, color of flash, etc. We will just show or hide them based on which special boilerplate is selected.

Initially this might be hardcoded but we probably will just do a table. So we can set up one table with all the new attributes we are adding, and these would just be value pairs. There would be no code in limesurvey using them.

So let's say we decide for those three special boilerplates our attributes are:
for VIDEO: number of seconds to show video
for NEUTRAL FACE: number of milliseconds to show face, which face to show (1,2, or 3)
for COLOR FLASH: color to show, number of flashes

So we'd have 3 special boilerplate types in one table:
video, neutral_face, color_flash

So we'd set up 5 new attributes in a table:
video - seconds
neutral_face - milliseconds
neutral_face - which_face
color_flash - color
color_flash - num_flashes

When the user added a new boilerplate question, it would display a dropdown with the options "Display Video, Show Neutral Face, Color Flash". No attributes would be shown though. They would be there, but hidden.

If the user selected "Color Flash" though, we would show the two color flash attributes: "Which color to flash?" and "How Many Flashes to Show?".

If the user changed the type to "Display Video", we would hide those attributes and instead show "How Many Seconds to Display Video?"

So basically we have just added a few attributes to the Boilerplate question. If they are not used, the boilerplate functions as before, so it's backwards compatible. The only custom code in LimeSurvey would be:
- code after LimeSurvey displays "Advanced Settings" for Boilerplates to load the dropdown and hidden questions, and modify the displayed attributes if the user changes the special boilerplate type.
- code when the user submits the form updating the question type that writes our new attributes to a database file. this code would also populate the boilerplate textbox with the appropriate javascript for the boilerplate type

I think that's it! Since the boilerplate javascript calls our custom script we can read the atttributes there and do everything else we need.

Does this sound like a good plan? I thought you guys might be interested as basically it lets someone use a boilerplate to call custom code to display the boilerplate and also allows each custom boilerplate to have its own set of attributes.

Our other option was to do the same thing but to copy the boilerplate question type to a new one instead. That one seemed much more invasive. The value of the other way is there would be minimal impact on your code and it would be easy for fix for new releases.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.099 seconds
Donation Image