Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wordpress surveyjs plugin - Cannot change textftield value #10

Open
Chatzimina opened this issue Mar 30, 2019 · 4 comments
Open

Wordpress surveyjs plugin - Cannot change textftield value #10

Chatzimina opened this issue Mar 30, 2019 · 4 comments
Labels
question Further information is requested

Comments

@Chatzimina
Copy link

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

@tsv2013 tsv2013 transferred this issue from surveyjs/survey-library Apr 1, 2019
@tsv2013
Copy link
Member

tsv2013 commented Apr 1, 2019

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

@tsv2013 tsv2013 added the question Further information is requested label Apr 1, 2019
@tsv2013
Copy link
Member

tsv2013 commented Apr 1, 2019

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

@Chatzimina
Copy link
Author

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!

@tsv2013
Copy link
Member

tsv2013 commented Apr 1, 2019

Yes, I fogot the $id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants