Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Value set via API not displayed

  • ployrich
  • ployrich's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 months 4 weeks ago #250777 by ployrich
Value set via API not displayed was created by ployrich
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.28.62
Own server or LimeSurvey hosting: self hosted
Survey theme/template: skelvanilla based
==================

Hi all,
so I am experiencing a somewhat frustrating situation. I am tasked with embedding iframes to collect infromation to a different service. Yet we need the collected information for expressionss throughout the survey. So I have a postMessage with the data being sent to a php file which sets the value via API.
The value is "there" = visible in the response table, BUT it is not being used for the filters.

I tried reloading the page with the Token to try and trigger the reading of existing responses, but that also didnt result in the expected behavior of "showing" or evaluating the API set value.

What is my oversight? Is that expected behavior? How can i workaround it?

Best regards and as always thank you in advance.

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 4 weeks ago #250794 by tpartner
Replied by tpartner on topic Value set via API not displayed
If you have access to the source of the iframes, you can use the JavaScript postMessage() method to send data from the iframe up to the top page.

- developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ployrich
  • ployrich's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 months 3 weeks ago #250931 by ployrich
Replied by ployrich on topic Value set via API not displayed
Thank you for the answer.

I am doing that, thats how i have the values available for the API call. The value also appears in the participants response data but and that is the problem I am trying to solve:

The value is not being used in the next question. Why is that happening?

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 3 weeks ago #250936 by tpartner
Replied by tpartner on topic Value set via API not displayed
I don't understand the need for the API. If you have access to the data, write them to (hidden?) questions via JavaScript.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ployrich
  • ployrich's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 months 3 weeks ago - 6 months 3 weeks ago #250959 by ployrich
Replied by ployrich on topic Value set via API not displayed
How do i do that via Javascript?

I didnt know that I could do that via js. tpartner to the rescue again..

At the moment I have the hidden question to be filled positioned before my iframe question. Different groups for group by group mode.
Last edit: 6 months 3 weeks ago by ployrich. Reason: less whitespace for readablity

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 3 weeks ago #250965 by tpartner
Replied by tpartner on topic Value set via API not displayed
It depends on the question type and where you have your JavaScript.

If, for example, the JS is in the source of a short-text question, it could look something like this:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Add a listener for messages
    window.addEventListener("message", receiveMessage, false);
 
    // Function fired when a message is received
    function receiveMessage(event) {
 
      // Test for the expected message origin 
      if (event.origin != 'https://pathToIframe') {
        return;
      }
 
      var messageData = event.data;
 
      // If the message data is JSON or an object, you may want to manipulate it here
 
      // Load the message data into the text input
      $('input:text.form-control:eq(0)', thisQuestion).val(messageData).trigger('keyup');
    }
  });
</script>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • ployrich
  • ployrich's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
6 months 21 hours ago #251557 by ployrich
Replied by ployrich on topic Value set via API not displayed
Thank you for the suggestion. I ended up using your solution partly.
Turns out I was mostly having issues preventing a bubbeling submit event from the iframe page.
 

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose