Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Answers: Use Placeholder instead of Default

Answers: Use Placeholder instead of Default 1 year 2 months ago #98466

  • gnb_lance
  • gnb_lance's Avatar
Is it possible to have html placeholder text in an answer rather than a default value? The use case - I'd like to provide guidance/tip without providing an answer. Thank you!


Attachment html5-palceholder.png not found

The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98476

  • JEfromCanada
  • JEfromCanada's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 39
  • Thank you received: 3
  • Karma: 0
When you create a question in Limesurvey, there is a secondary input field called "Help". That field seems tailor-made for what you are looking for.

The only issue you might still have is HOW and WHEN to display the guidance/tip. For that, you might need to create your own survey template (so, for example, the hint will only be displayed during a mouseover, rather than being displayed by default).
The administrator has disabled public write access.
The following user(s) said Thank You: gnb_lance

Answers: Use Placeholder instead of Default 1 year 2 months ago #98477

  • gnb_lance
  • gnb_lance's Avatar
In my wizard, the Help is more of a detailed explanation, and the placeholder is used to guide them on the proper input. I'm onto a (hacky) way to do it - qanda_helper.php generates the html and I'm able to replace 'value' with 'placeholder'. The trick is just tracking down the correct places to do this. I've found one for numeric inputs so far.
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98486

  • gnb_lance
  • gnb_lance's Avatar
I'm not certain this comes without repercussion, but the code below hacks the php code which generates html to use placeholder rather than value. A more complex solution is required if a mixture of defaults and placeholders for the same types is needed.

To change numerical default 'value' to 'placeholder', edit @3748:
//. "id=\"answer{$ia[1]}\" value=\"{$fValue}\" onkeyup=...
. "id=\"answer{$ia[1]}\" placeholder=\"{$fValue}\" onkeyup=...

To change shortfreetext default 'value' to 'placeholder', edit @3947:
//$answer .= " value=\"$dispVal\"";
$answer .= " placeholder=\"$dispVal\"";

To change longfreetext and hugefreetext default 'value' to 'placeholder', edit @4041/4116:
//  .'rows="'.$drows.'" cols="'.$tiwidth.'" '.$maxlength.' onkeyup="'.$checkconditionFunction.'(this.value, this.name, this.type)" >';
//  if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) {$answer .= str_replace("\\", "", $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]);}
//  $answer .= "</textarea></p>\n";
    .'rows="'.$drows.'" cols="'.$tiwidth.'" '.$maxlength.' onkeyup="'.$checkconditionFunction.'(this.value, this.name, this.type)" ';
    if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) {
        $answer .= 'placeholder="';
        $answer .= str_replace("\\", "", $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]);
        $answer .= '"';
    }
    $answer .= "></textarea></p>\n";
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98488

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1119
  • Thank you received: 253
  • Karma: 78
Hello,

IMO, hacking such important file (qanda.php) is a not a good solution and you may have to replace (and adapt) your changes after any LS major update.

For people needing such feature for some questions it's possible to do it using few javascript lines, something like (not tested):
<script type="text/javascript" charset="utf-8"> 
$(document).ready(function() {
$('#answer123X456X789').attr('value', 'Employee first name...');
$('#answer123X456X789').attr('onfocus', 'if (this.value == this.defaultValue) { this.value = ""; }');	
}); 
</script>
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98512

  • gnb_lance
  • gnb_lance's Avatar
Thanks Ben - Completely agree. My solution is especially problematic as revisiting any page turns data they've entered back into a place holder. Which file would you suggest adding the JS to?
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98514

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1119
  • Thank you received: 253
  • Karma: 78
place the js in the source of the question or question help ...
Obviously numeric IDs (SGQA code) in my example #answer123X456X789, have to be adapted for each question...
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
The administrator has disabled public write access.
The following user(s) said Thank You: gnb_lance

Answers: Use Placeholder instead of Default 1 year 2 months ago #98531

  • gnb_lance
  • gnb_lance's Avatar
Thanks Ben. Your concept is working - I changed it slightly to set the placeholder attribute (and no longer define a default):
<script type="text/javascript" charset="utf-8"> 
$(document).ready(function() {
$('#answer216511X3X1').attr('placeholder', 'Employee first name...');	
}); 
</script>

I think hardcoding the IDs is probably asking for trouble as they're based on the group and question id which change with reordering. It's also tedious.

I'm thinking about something more dynamic - does this.defaultValue actually exist? I couldn't get it to work but I think it would be key.
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98532

  • gnb_lance
  • gnb_lance's Avatar
Here's where I'm at now. Each question's default value can be prefixed with "***" to make it a placeholder instead. This scales nicely, and leaves default value functionality if desired.
<script type="text/javascript" charset="utf-8"> 
$(document).ready(function() {
 
var specialPrefix = "***";
 
var inputs = document.getElementsByTagName("input");
for (x=0;x<=inputs.length;x++){
   id = inputs[x].getAttribute("id");
   if(id.indexOf("answer")==0){
      var value = $('#'+id).attr('value');
      if (value.lastIndexOf(specialPrefix, 0) == 0){
         $('#'+id)
         .attr('value', '')
         .attr('placeholder', value.substring(specialPrefix.length));
      }
   }
}
}); 
</script>
The administrator has disabled public write access.

Answers: Use Placeholder instead of Default 1 year 2 months ago #98534

  • Ben_V
  • Ben_V's Avatar
  • OFFLINE
  • Platinum Lime
  • Posts: 1119
  • Thank you received: 253
  • Karma: 78
...as they're based on the group and question id which change with reordering

Using LS ≥1.92, {SGQ} keyword is doing the job, so you can adapt js codes this way:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
 
		var SGQ = '{SGQ}';
 
		$('#answer'+SGQ).attr(…..
 
	});
</script>
Benoît

goo.gl/Bw5iM => Recherche GG dans le forum français (remplacer "exemple" dans la barre de recherche)
goo.gl/WX8PH => GG search for english forum (Replace "example" in the search bar)
goo.gl/IxiGu => Búsqueda en el foro en español (Cambiar "ejemplo" en la barra de...
Last Edit: 1 year 2 months ago by Ben_V.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.330 seconds
Donation Image