Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:
  • Seite:
  • 1
  • 2

THEMA: Answers: Use Placeholder instead of Default

Answers: Use Placeholder instead of Default 1 Jahr 3 Monate her #98466

  • gnb_lance
  • gnb_lances 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!


Anhang html5-palceholder.png nicht gefunden

Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 3 Monate her #98476

  • JEfromCanada
  • JEfromCanadas Avatar
  • OFFLINE
  • Junior Lime
  • Beiträge: 39
  • Dank erhalten: 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).
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: gnb_lance

Answers: Use Placeholder instead of Default 1 Jahr 3 Monate her #98477

  • gnb_lance
  • gnb_lances 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 3 Monate her #98486

  • gnb_lance
  • gnb_lances 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";
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 3 Monate her #98488

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1122
  • Dank erhalten: 255
  • Karma: 79
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...
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98512

  • gnb_lance
  • gnb_lances 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?
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98514

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1122
  • Dank erhalten: 255
  • Karma: 79
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...
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Folgende Benutzer bedankten sich: gnb_lance

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98531

  • gnb_lance
  • gnb_lances 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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98532

  • gnb_lance
  • gnb_lances 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>
Der Administrator hat öffentliche Schreibrechte deaktiviert.

Answers: Use Placeholder instead of Default 1 Jahr 2 Monate her #98534

  • Ben_V
  • Ben_Vs Avatar
  • OFFLINE
  • Platinum Lime
  • Beiträge: 1122
  • Dank erhalten: 255
  • Karma: 79
...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...
Letzte Änderung: 1 Jahr 2 Monate her von Ben_V.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
  • Seite:
  • 1
  • 2
Moderatoren: ITEd
Ladezeit der Seite: 0.360 Sekunden
Donation Image