- Posts: 6
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Add Colors in questions
- mistercitrus
- Topic Author
- Offline
- New Member
Just need to add some colors to a number of questions, the entire survey would share the same color scheme and each question would always have 5 responses if that makes things simpler.
Open to other solutions such as graphic 'buttons' or just colored text to
The closest I've seen is this example -
LouisGac wrote: Hi,
It should be possible to adapt old survey template with the new system without too much difficulties.
We're working on it for the future.
Here basically the work that must be done (you can help with it) :
1. All the question types, less arrays, have now separated views :
github.com/LimeSurvey/LimeSurvey/tree/ma...ews/survey/questions
In a close future, this will give the possibility to any LimeSurvey user with some skill in PHP/JS/CSS to add new question rendering, with its own HTML, JS files, and CSS, and to share them as question modules.
Have a look to the YES/NO question or GENDER question and their new question attribute to see how it works. Basically, for gender question, you can see that we added new 'button' views :
github.com/LimeSurvey/LimeSurvey/tree/ma...vey/questions/gender
accessible via the 'display' question attribute.
2. So, we must finish to export the array question HTML to view
3. Then we must add the old question HTML of 2.0x as views accessible via a display option
For now, I will advise you just to build new template on the base of one of the new ones. They use Bootstrap (easy to use), and are fully responsive.
- Joffm
- Offline
- LimeSurvey Community Team
- Posts: 12790
- Thank you received: 3940
here is a solution for array. Only example with three colored columns.
Insert into the sourcecode of the question:
<style type="text/css"> .answer_cell_001, .answer_cell_1 { Background-color: red !important; } .answer_cell_003, .answer_cell_3 { Background-color: yellow !important; } .answer_cell_006, .answer_cell_6 { Background-color: #DDDDDD !important; } </style>
And the smileys? Well, that's something different.
Of course I used an existing question of one of our questionnaires.
Volunteers are not paid.
Not because they are worthless, but because they are priceless
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10634
- Thank you received: 3698
1) Assign a question class "coloured-array".
2) Add something like this to the end of template.js:
$(document).ready(function() { $('.coloured-array').each(function(i) { // Assign column-specific classes $('table.subquestion-list tr', this).each(function(i) { $('> *:gt(0)', this).each(function(i){ $(this).addClass('column-'+(i+1)); }); }); }); });
3) Add something like this to the end of template.css:
.coloured-array .column-1 { background-color: #FF5B5B;} .coloured-array .column-2 { background-color: #FF9B57;} .coloured-array .column-3 { background-color: #F4F781;} .coloured-array .column-4 { background-color: #99FDA3;} .coloured-array .column-5 { background-color: #53C170;}
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- mistercitrus
- Topic Author
- Offline
- New Member
- Posts: 6
- Thank you received: 0
Just having some trouble getting it to activate the css changes
I've created a new template (copy of default) and made those changes, adding
/*** Array Colors are defined here***/ .coloured-array .column-1 { background-color: #FF5B5B;} .coloured-array .column-2 { background-color: #FF9B57;} .coloured-array .column-3 { background-color: #F4F781;} .coloured-array .column-4 { background-color: #99FDA3;} .coloured-array .column-5 { background-color: #53C170;}
to the end of the new template's css/template.css and then
$('.coloured-array').each(function(i) { // Assign column-specific classes $('table.subquestion-list tr', this).each(function(i) { $('> *:gt(0)', this).each(function(i){ $(this).addClass('column-'+(i+1)); }); }); });
just before the error section of scripts/template.js (line 138)
my array questions all have "coloured-array" without quotes in the CSSClass(es) in the advanced settings. I have gone over it a couple of times and don't think I've missed anything but when I perform a preview of the survey or question group I can see no changes and the source for the page if I view it doesn't show the entries in the css.
- mistercitrus
- Topic Author
- Offline
- New Member
- Posts: 6
- Thank you received: 0
- mistercitrus
- Topic Author
- Offline
- New Member
- Posts: 6
- Thank you received: 0
- Els_Severens
- Offline
- New Member
- Posts: 4
- Thank you received: 0
I also want to do something like that, but I cannot find what names my cells have. Can you tell me where I can find that?
thanks!
- Joffm
- Offline
- LimeSurvey Community Team
- Posts: 12790
- Thank you received: 3940
you want to do something like that. What exactly?
And to answer your question about the names of cells:
Use a web inspector which is included in all new browsers.
But better to tell us what is different from the solution tpartner provided.
And - of course - your LS version.
Regards
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
- Filippo_nov
- Offline
- New Member
- Posts: 8
- Thank you received: 0
I tried your solution and It works great!
What about dual scale arrays?
How could I set every column/header colours?
Thank you!
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10634
- Thank you received: 3698
Can you provide a small sample survey (.lss file) containing only the relevant question?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- Filippo_nov
- Offline
- New Member
- Posts: 8
- Thank you received: 0
Using this:
$(document).on('ready pjax:scriptcomplete',function(){
$(document).ready(function() {
$('.coloured-array').each(function(i) {
// Assign column-specific classes
$('table.subquestion-list tr', this).each(function(i) {
$('> *:gt(0)', this).each(function(i){
$(this).addClass('column-'+(i+1)); }); }); });});
+
.coloured-array .column-2 { background-color: #FFBA70;}
I was able to change correctly the colour of the columns of a single scale array.
I tried to use this code also for dual scale array but it doesnt't work properly (ie. it changes also the background color of the headers).
I'd like to change the background color only of columns and not of the header (see image attached).
And here's the question.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10634
- Thank you received: 3698
JavaScript:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ $('.coloured-array.array-flexible-duel-scale').each(function(i) { // Assign column-specific classes $('table.subquestion-list tr.ls-heading:not(.groups)', this).each(function(i) { $('.answer-text', this).each(function(i){ $(this).addClass('column-'+(i+1)); }); }); }); }); </script>
CSS:
<style type="text/css"> .coloured-array.array-flexible-duel-scale .column-1 { background-color: #FF9B57;} /* Orange */ .coloured-array.array-flexible-duel-scale .column-2 { background-color: #F4F781;} /* Yellow*/ .coloured-array.array-flexible-duel-scale .column-3 { background-color: #53C170;} /* Green*/ .coloured-array.array-flexible-duel-scale .column-4 { background-color: #FF9B57;} /* Orange */ .coloured-array.array-flexible-duel-scale .column-5 { background-color: #F4F781;} /* Yellow*/ .coloured-array.array-flexible-duel-scale .column-6 { background-color: #53C170;} /* Green*/ .coloured-array.array-flexible-duel-scale .column-7 { background-color: #FF5B5B;} /* Red*/ </style>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.