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

Restore Survey Answers #404

Closed
atton16 opened this issue May 22, 2019 · 6 comments
Closed

Restore Survey Answers #404

atton16 opened this issue May 22, 2019 · 6 comments

Comments

@atton16
Copy link

atton16 commented May 22, 2019

Hi,

I am developing the survey system based on enketo-core as you already knows it.

Right at the time the form validation is done, we can get the data using $scope.form.getDataStr().

I then tried to use this data by convert the return string to XMLDocument as the library suggested. Then use the data like followings:

var dataStrFromValidation = '...';

var data = {
  modelStr: $scope.loaded_model,
  instanceStr: 'answer',
  submitted: false,
  external: [{
    id: 'answer',
    xml: (new window.DOMParser()).parseFromString(dataStrFromValidation, 'text/xml'),
  }],
  session: {}
};

However, there seems to be the problem with parsing XMLDocument.

See the screenshot below:

Screen Shot 2019-05-22 at 15 15 48

Here is the sample data returned from validation

<trip-end-survey_v5
  xmlns:jr="http://openrosa.org/javarosa"
  xmlns:odk="http://www.opendatakit.org/xforms"
  xmlns:orx="http://openrosa.org/xforms"
  id="trip-end-survey_v5"
  version="veMfY6eZ2W9qoGhmfzJX8F">
  <start>2019-05-21T21:14:28.317+07:00</start>
  <end>2019-05-21T21:14:28.320+07:00</end>
  <group_vs9ga59>
    <trip_purpose_main>1</trip_purpose_main>
    <trip_purpose_sub_category/>
  </group_vs9ga59>
  <group_ee9rk21>
    <travel_mode_main>vehicle</travel_mode_main>
    <travel_mode_sub_category>4</travel_mode_sub_category>
    <Total_people_in_trip_party>1</Total_people_in_trip_party>
    <Non_household_member_s_on_trip>2</Non_household_member_s_on_trip>
    <Household_member_s_on_trip>5</Household_member_s_on_trip>
    <group_bn3jd79>
      <Vehicle_trip_with_2_Driver_or_passenger>1</Vehicle_trip_with_2_Driver_or_passenger>
      <Vehicle_trip_Parking_location>5</Vehicle_trip_Parking_location>
      <Parking_cost>10</Parking_cost>
    </group_bn3jd79>
    <Rail_payment_method/>
    <Transit_fees_AUD/>
    <Taxi_fees/>
  </group_ee9rk21>
  <__version__>vLX8oPb8xP2pLvxNBagygU</__version__>
  <_version_>vwpCadzPYVsW9XEjxZzwnR</_version_>
  <_version__001>vSuFDQ2DcmpRpKcRfSXReq</_version__001>
  <_version__002>veMfY6eZ2W9qoGhmfzJX8F</_version__002>
  <meta>
    <instanceID>uuid:25c045ff-e8e6-4799-acdb-7d15f8f80b70</instanceID>
  </meta>
</trip-end-survey_v5>
@shankari
Copy link
Contributor

shankari commented May 22, 2019

@atton16 yes it is pretty clear that something is undefined. not sure whether it is the DOMParser or the method or the string. Maybe add some more logging/check the debugger to figure it out?

Also, the external field is not intended to pre-populate the values in the form; it is intended to pre-populate the options in the form - e.g. list of countries or list of cities.
http://xlsform.org/en/#external-xml-data
or more generally, https://duckduckgo.com/?q=xlsforms+external&t=ffsb&ia=web

@shankari
Copy link
Contributor

There is also some additional discussion and a live example in XLSForm/pyxform#30

@shankari
Copy link
Contributor

FYI, I have confirmed that the DOMParser is available on both Firefox and Safari - e.g.

Screen Shot 2019-05-22 at 10 19 44 AM

@atton16
Copy link
Author

atton16 commented May 23, 2019

There is also some additional discussion and a live example in XLSForm/pyxform#30

Thanks, I am looking at it now.

@atton16
Copy link
Author

atton16 commented May 23, 2019

It appears that the correct field is instanceStr.

So the code should looks like this:

var dataStrFromValidation = '...';

var data = {
  modelStr: $scope.loaded_model,
  instanceStr: dataStrFromValidation,
  submitted: false,
  external: [],
  session: {}
};

Very simple!!

@atton16 atton16 closed this as completed May 23, 2019
@shankari
Copy link
Contributor

Closing, implemented in e-mission/e-mission-phone#572

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

No branches or pull requests

2 participants