enketo-core icon indicating copy to clipboard operation
enketo-core copied to clipboard

add method to obtain compact state of model

Open MartijnR opened this issue 5 years ago • 8 comments

here is a start: https://github.com/alxndrsn/xform-conmpact-record-representation-for-sms.js

MartijnR avatar Oct 24 '18 15:10 MartijnR

Considering how little code is required, let's add such a method to Enketo Core, for apps to use.

  • adding methods for delimiter,
  • avoiding jQuery

MartijnR avatar Oct 24 '18 15:10 MartijnR

How do you think this would best fit? As an option on form.getDataStr()? e.g. form.getDataStr({ compact:true })

Any thoughts on how to parse XML without using jquery? jquery.parseXML(modelStr) (which I know is still jquery) has issues with undefined XML namespaces, which using jquery(modelStr) does not.

adding methods for delimiter

Does this mean allowing the delimiter to be set when calling form.getDataStrCompact()?

alxndrsn avatar Oct 24 '18 16:10 alxndrsn

@MartijnR I'm also interested in your opinion of this:

https://github.com/alxndrsn/xform-conmpact-record-representation-for-sms.js/blob/master/test/index.spec.js#L44-L46

It will complicate code a bit to include fields which don't have a value set. For medic's uses, I don't think it's an essential feature, although deviating from the spec may not be desirable for enketo.

alxndrsn avatar Oct 24 '18 16:10 alxndrsn

As an option on form.getDataStr()? e.g. form.getDataStr({ compact:true })

Yes, that sounds great!

parse XML

We're using this: https://github.com/enketo/enketo-core/blob/master/src/js/Form-model.js#L120

allowing the delimiter to be set

I meant just to extract it from the model like these (also for prefix): https://github.com/enketo/enketo-core/blob/master/src/js/Form-model.js#L62-L91, just for consistency.

MartijnR avatar Oct 24 '18 16:10 MartijnR

although deviating from the spec may not be desirable for enketo

Yes, we should follow the spec. It might be worth starting a conversation on changing the spec though. Maybe this is to make a distinction between a user changing a default value to "" vs. not answering?

MartijnR avatar Oct 24 '18 16:10 MartijnR

Yes, we should follow the spec. It might be worth starting a conversation on changing the spec though. Maybe this is to make a distinction between a user changing a default value to "" vs. not answering?

I think this actually relates to non-relevant fields - in the first compact example in the spec, <firstname> is not included in the full response, but fn|| is included in the compact representation. Although perhaps this is actually a mistake in the spec, and an empty <firstname></firstname> element should be included in the first example?

alxndrsn avatar Oct 25 '18 11:10 alxndrsn

yes totally, right!

MartijnR avatar Oct 25 '18 16:10 MartijnR

Spec changed or in the process of being changed pending comments from you! https://github.com/opendatakit/xforms-spec/pull/215

MartijnR avatar Oct 26 '18 22:10 MartijnR