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

select_one_from_file gets a blank option that is just an underscore

Open MattFoy opened this issue 6 years ago • 5 comments

I have a field of type "select_one_from_file list.csv".

In the model XML string I pass to Enketo I provide a secondary instance like so: ...<instance id="list"><root xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms"><item><name>Employee</name><label>Employees</label></item>...<item><name>WriteIn</name><label>Write-in</label></item></root></instance>...

Everything looks like, but when Enketo renders the options, the HTML ends up looking like: <div class="option-wrapper"><label class="itemset-template" data-items-path="instance('list')/root/item"><input type="radio" name="/in/list" data-name="/in/list" data-required="true()" data-type-xml="select1" value=""></label><span class="itemset-labels" data-value-ref="name" data-label-ref="label"></span><label><input type="radio" name="/in/list" data-name="/in/list" data-required="true()" data-type-xml="select1" value="_"><span class="option-label active" data-option-value="_">_</span></label><label><input type="radio" name="/in/list" data-name="/in/list" data-required="true()" data-type-xml="select1" value="Employee"><span class="option-label active" data-option-value="Employee">Employees</span></label>...<label data-checked="true"><input type="radio" name="/in/list" data-name="/in/list" data-required="true()" data-type-xml="select1" value="WriteIn"><span class="option-label active" data-option-value="WriteIn">Write-in</span></label></div>

As you can see, there's mysteriously an option for the value "_" is there, with a display value of "_".

So... where is this underscore option coming from? Any ideas?

Thanks!

MattFoy avatar Dec 12 '18 21:12 MattFoy

I figured out a workaround... I added a new piece of metadata to the external instance, so now it looks like: <instance id="list"><root xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms"><item><name>Employee</name><label>Employees</label><display>1</display></item>...<item><name>WriteIn</name><label>Write-in</label><display>1</display></item></root></instance>

And added a choices_filter column to the XLSForm with: display = '1'... so now Enketo hides the underscore. A bit silly, but functional.

MattFoy avatar Dec 12 '18 21:12 MattFoy

It's probably this ODK Validate workaround: https://github.com/XLSForm/pyxform/issues/87#issuecomment-249008655 (some dummy content that pyxform adds). Check the XForm to confirm. I think this workaround can actually be removed from pyxform now (if it hasn't been already) as I think ODK Validate has been amended.

This dummy content should be automatically removed by Enketo though, so something is going wrong.

MartijnR avatar Dec 12 '18 21:12 MartijnR

Here's the field's HTML before I run the Enketo Core initialization: <fieldset><legend><span lang="en" class="question-label active" data-itext-id="/in/list:label">List</span><span class="required">*</span></legend><div class="option-wrapper"><label class="itemset-template" data-items-path="instance(''list'')/root/item[display = ''1'']"><input type="radio" name="/in/list" data-name="/in/list" data-required="true()" data-type-xml="select1" value=""/></label><span class="itemset-labels" data-value-ref="name" data-label-ref="label"></span></div></fieldset>

So... no underscores in sight at this point (which is after both xls2xform and enketo-transformer have done their thing).

MattFoy avatar Dec 12 '18 21:12 MattFoy

Ahh, you're right on the money! Here's the placeholder node from the xform: <instance id="list" src="jr://file-csv/list.csv"><root><item><name>_</name><label>_</label></item></root></instance>.

I thought I was ignoring that and injecting my own populated instance... but it turns out I ended up with two duplicate instances in my model XML: <instance id="list" src="jr://file-csv/list.csv"><root xmlns:jr="http://openrosa.org/javarosa" xmlns:odk="http://www.opendatakit.org/xforms" xmlns:orx="http://openrosa.org/xforms"><item><name>_</name><label>_</label></item></root></instance> much earlier, and then my "real" one further down.

Thanks!

MattFoy avatar Dec 12 '18 21:12 MattFoy

Thanks for following up! So it sounds like this may still be a bug in Enketo though. Will check.

MartijnR avatar Dec 12 '18 23:12 MartijnR