surveyjs-wordpress icon indicating copy to clipboard operation
surveyjs-wordpress copied to clipboard

Wordpress surveyjs plugin - Cannot change textftield value

Open Chatzimina opened this issue 6 years ago • 4 comments

Hello everyone,

I have a weird problem. I have used surveyjs plugin with a wordpress site (version : 5.1.1) and I have created a quesionnaire but I would like to keep which user is completing the questionnaire. I created a textfield and tried to complete automatically (because the user may not complete it properly) it by using this code:

  var textfield = document.getElementsByClassName('sv_q_text_root')[0];
  textfield[i].value = '<?php $current_user = wp_get_current_user(); echo $current_user->user_email ;?>';

Although I see the email shown inside the textfield when I save the survey it is not saved in the results. Then if I add by pressing in the keybord an extra letter after the email the result is saved. For example if I add by javascript the "[email protected]" in the textfiled it is not saved but if i write a letter by keyboard after it like this "[email protected]" it is saved.

Then I tried to simulate a keyboard press like this :

   jQuery(function($) {
      $( "#sv_q_text_root" ).trigger(
      jQuery.Event( 'keyup', { keyCode: "65", which: "65" } )
   )});

but still it doesn't save. If also you know another way to save the users with the results, I couldn't find something about wordpress. Thank you

Chatzimina avatar Mar 30 '19 16:03 Chatzimina

@Chatzimina I've transefrred the issue into the corresponding repository.

tsv2013 avatar Apr 01 '19 05:04 tsv2013

I think you can set corresponding data directly into the first question of a survey somethere in the initSurvey function, most likely here https://github.com/surveyjs/surveyjs-wordpress/blob/master/initializer.php#L171

by the following code:

  var question = survey.getAllQuestions()[0];
  question.value = '<?php $current_user = wp_get_current_user(); echo $current_user->user_email ;?>';

Hope this helps

tsv2013 avatar Apr 01 '19 05:04 tsv2013

It worked like this:

 var question = window.survey<?php echo $id ?>.getAllQuestions()[0];
 question.value = '<?php $current_user = wp_get_current_user(); echo $current_user->user_email ;?>';

thank you very much!

Chatzimina avatar Apr 01 '19 08:04 Chatzimina

Yes, I fogot the $id

tsv2013 avatar Apr 01 '19 08:04 tsv2013