Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

How to add custom css and js files

  • LouisGac
  • LouisGac's Avatar
  • New Member
  • New Member
More
8 years 6 months ago #142438 by LouisGac
Replied by LouisGac on topic How to add custom css and js files
Yep I'm in the LS Team, and I'm the one who exported all the HTML into views and added the view override system.

At the beginning, I wanted to add the button layout as an alternative for the radio/checkbox for each concerned question type. But finally, I did it for gender only: I had other priorities.

So, yes, if you do it fine, we could integrate your code into core, and we could add a "button layout" option in the radio list's advanced options.

As soon as we rewrite the question views with a templating language (probably twig), the view override system will be official, documented, and we'll offer you a place to share your experiments. That could happen before the end of the year.

In a further future, when we'll have question object, it will be easy to transform your custom views in new question types (that could be share/sold and uploaded in any LimeSurvey installation).
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago #142439 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
Great.. A boss once told me, "Kevin, I take care of you because you take care of me." So, I'll help you because you've helped me. So, for production, should I do it as an override or copy the function "do_list_radio" in qandra_helper.php.

And copy survey/questions/radiolist to / survey/questions/list_custom/ and edit the code?

I'm placing // Kevin on every line I change so it will be easy to find the changes.
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • New Member
  • New Member
More
8 years 6 months ago - 8 years 6 months ago #142440 by LouisGac
Replied by LouisGac on topic How to add custom css and js files
No you don't need to touch anymore qanda_helper now.
Here how it works now:
github.com/LimeSurvey/LimeSurvey/blob/ma...lper.php#L6266-L6295

Quick explanation:
if overwrite_question_views is true in template the lime survey config allow_templates_to_overwrite_views, then it will look if the template have its own view file to render it (if not, it render the core view file).
Last edit: 8 years 6 months ago by LouisGac.
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago #142441 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
This link had some nice stuff for mobile devices. www.w3schools.com/jquerymobile/jquerymobile_navbars.asp
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago #142443 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
It's not pulling from my edited answer_row_other.php
I added <!-- Kevin --> and viewing the source of the webpage does not show it.

Directory structure: /upload/templates/mobile/views/survey/questions/listradio/rows

config.xml:
<overwrite_question_views>true</overwrite_question_views>

config.php
'config'=>array(
'debug'=>0,
'debugsql'=>0,
'allow_templates_to_overwrite_views'=>1
)

Question type is "List (radio)"
The topic has been locked.
  • LouisGac
  • LouisGac's Avatar
  • New Member
  • New Member
More
8 years 6 months ago #142445 by LouisGac
Replied by LouisGac on topic How to add custom css and js files
To be sure the custom views are loaded, I'd advise you to add something very visible in the view, like a: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" :laugh:

Also, be sure that you're using the right template in your survey... file permissions, etc

Be sure that what is going wrong is a very little thing.
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago - 8 years 6 months ago #142448 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
It must not be using the correct template because I edited the startpage.pspl and my change did not appear. I'll be back :) <saying with Arnold Arnold Schwarzenegger's accent>
Last edit: 8 years 6 months ago by Kevin01.
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago #142449 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
Found it... I added a line to answer_row.php
It's pulling from the correct place. Now, lets see if I can make cool buttons :)
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago - 8 years 6 months ago #142450 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
Its close... It toggles left to right.. I'd like it to toggle up and down. I'll see what I can do but this might be in the bootstrap file?
Last edit: 8 years 6 months ago by Kevin01.
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago #142451 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
Closer:


<!-- answer_row -->
<!--
<div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item radio' <?php echo $sDisplayStyle; ?> >
<input
class="radio"
type="radio"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
<label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>

-->

<div class="btn-group" data-bs-toggle="buttons">
<label class="btn btn-primary">
<input
type="radio"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"

<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>

<label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>
</div>
Attachments:
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago - 8 years 6 months ago #142456 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
Do you know what I am missing in the code that is not allowing it to save a value? I attached images.

Reference: www.w3schools.com/bootstrap/tryit.asp?fi...tton_block&stacked=h

Original Code that works:

<?php
/**
* Multiple Choice Html : item row
*
* @var $name
* @var $code
* @var $answer
* @var $checkedState
* @var $myfname
*/
?>

<!-- answer_row -->
<div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item radio' <?php echo $sDisplayStyle; ?> >
<input
class="radio"
type="radio"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
<label for="answer<?php echo $name.$code; ?>" class="control-label radio-label"></label>

<!--
The label text is provided inside a div,
so final user can add paragraph, div, or whatever he wants in the subquestion text
This field is related to the input thanks to attribute aria-labelledby
-->
<div class="label-text label-clickable" id="label-answer<?php echo $name.$code; ?>">
<?php echo $answer; ?>
</div>
</div>





My code that does not work:
<?php
?>

<!-- answer_row -->

<div id='javatbd<?php echo $myfname; ?>' class='col-xs-12 form-group answer-item radio-item radio' <?php echo $sDisplayStyle; ?> >

<div class="container-fluid">
<input
class="btn btn-primary btn-block"
type="button"
value="<?php echo $code; ?>"
name="<?php echo $name; ?>"
id="answer<?php echo $name.$code; ?>"
<?php echo $checkedState;?>
onclick="if (document.getElementById('answer<?php echo $name; ?>othertext') != null) document.getElementById('answer<?php echo $name; ?>othertext').value='';checkconditions(this.value, this.name, this.type)"
aria-labelledby="label-answer<?php echo $name.$code; ?>"
/>
</div>
</div>
Last edit: 8 years 6 months ago by Kevin01.
The topic has been locked.
  • Kevin01
  • Kevin01's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
8 years 6 months ago #142457 by Kevin01
Replied by Kevin01 on topic How to add custom css and js files
This might be easier to follow.
Attachments:
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose