Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi
  • Page :
  • 1
  • 2

SUJET : Answers: Use Placeholder instead of Default

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98466

  • gnb_lance
  • Portrait de gnb_lance
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!


La pièce jointe html5-palceholder.png est absente ou indisponible

L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98476

  • JEfromCanada
  • Portrait de JEfromCanada
  • Hors ligne
  • Junior Lime
  • Messages : 39
  • Remerciements reçus 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).
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: gnb_lance

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98477

  • gnb_lance
  • Portrait de gnb_lance
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98486

  • gnb_lance
  • Portrait de gnb_lance
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";
L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98488

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 933
  • Remerciements reçus 193
  • Karma: 62
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...
L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98512

  • gnb_lance
  • Portrait de gnb_lance
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?
L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98514

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 933
  • Remerciements reçus 193
  • Karma: 62
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...
L'administrateur a désactivé l'accès en écriture pour le public.
Cet utilisateur a été remercié pour son message par: gnb_lance

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98531

  • gnb_lance
  • Portrait de gnb_lance
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98532

  • gnb_lance
  • Portrait de gnb_lance
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>
L'administrateur a désactivé l'accès en écriture pour le public.

Answers: Use Placeholder instead of Default il y a 8 mois 3 semaines #98534

  • Ben_V
  • Portrait de Ben_V
  • Hors ligne
  • Platinum Lime
  • Messages : 933
  • Remerciements reçus 193
  • Karma: 62
...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...
Dernière édition: il y a 8 mois 3 semaines par Ben_V.
L'administrateur a désactivé l'accès en écriture pour le public.
  • Page :
  • 1
  • 2
Modérateurs: ITEd
Temps de génération de la page : 0.377 secondes
Donation Image