Welcome, Guest
Username: Password: Remember me

TOPIC: Empty div and span generated by core

Empty div and span generated by core 3 weeks 4 days ago #110598

  • tammo
  • tammo's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 33
  • Thank you received: 2
  • Karma: 1
Currently we are defining a Bootstrap based theme for Limesurvey (which we will gladly share with interested people here).

We ran into the problem that at several places in the generated HTML empty divs and spans are generated. For example: when you have a non-mandatory question and you do not want to display the question code nor the question number, the following HTML is generated.

For example:

<h3 class="panel-title">
<span class="text-danger"></span>
<span class="question-code">pops01</span>
<span class="question-text"><span class="question-number"></span>
<p>
Heeft u opvang thuis na de operatie?</p>
<p>
TEST</p>
</span>
</h3>

The problem is that when you want to position element very precise with padding/margin, these paddings/margins also show up when the elements are not there. For example: when a question is not-mandatory, the padding/margins that you declare for the class .text-danger still show up, because the empty element is generated.

We have tackled this with javascript, but this is actually bad practice: all empty HTML is still generated and transferred to be deleted later.

Would it be possible to change the code thus that empty divs and spans are not generated into the HTML?
The administrator has disabled public write access.

Empty div and span generated by core 3 weeks 4 days ago #110602

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6222
  • Thank you received: 791
  • Karma: 238
HI,

1st solution : use :empty css class : developer.mozilla.org/docs/Web/CSS/:empty
2nd : use EM to remove undeeded div and span git.sondages.pro/?p=skeletonquest.git/.g...5f8808f50;hb=HEAD#l8

Some empty div can not be removed : Javascrpt update it.

Denis
The administrator has disabled public write access.
The following user(s) said Thank You: tammo, Ben_V

Empty div and span generated by core 3 weeks 4 days ago #110610

  • tammo
  • tammo's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 33
  • Thank you received: 2
  • Karma: 1
Hi Denis,

we did use Javascript and solved the problem, but still it is more elegant to build in a check if an element contains data and not render it when it does nor contain data. That way you avoid empty HTML which needs to be hidden by extra javascript.

Thanks for the :empty tip, I did not know that one.

Tammo
The administrator has disabled public write access.

Empty div and span generated by core 3 weeks 4 days ago #110611

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6222
  • Thank you received: 791
  • Karma: 238
But the <span class="text-danger"></span> is from your template, we don't use it.

For :
<span class="question-number"></span>
{if(!is_empty(QUESTION_NUMBER) or !is_empty(QUESTION_CODE),"<span class='qnumcode'>"+QUESTION_NUMBER+" "+QUESTION_CODE+"</span>","")}
It's not javascript : QUESTION_NUMBER and QUESTION_CODE are static value : then it's removed from HTML (if survey setings disable show).

Like the :
{if(!is_empty(QUESTION_MANDATORY),"<span class='asterisk'>"+QUESTION_MANDATORY+"</span>","")}

It's a template issue: not a LimeSUrvey issue : limesurvey just add *, nothing else.

We have a lot of problem elsewhere ... please : patch core ;)
The administrator has disabled public write access.
The following user(s) said Thank You: tpartner

Empty div and span generated by core 3 weeks 4 days ago #110629

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4069
  • Thank you received: 746
  • Karma: 341
Yes Denis, great tip about putting qualifiers around elements in the template files.

Note that :empty does not work in IE8 and earlier (if anyone cares).


.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Empty div and span generated by core 3 weeks 4 days ago #110635

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6222
  • Thank you received: 791
  • Karma: 238
tpartner wrote:
Yes Denis, great tip about putting qualifiers around elements in the template files.
Thanks,

The only potential issue is : "More memory for PHP". Think using EM use a lot of memory, we really need to work on cache for templating and survey start.

Denis
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.270 seconds
Donation Image