I would like to customize the RangeWidget for my project so that I can show text at the ends of the seek bar rather than numbers as is the current functionality. I would like not to have to change the
javarosa library or
pyxform package, and I hope I can put all my code additions inside the
RangeWidget class or its subclasses in ODK Collect. I would prefer to do this even if it tramples on the software design.
My thought is to add custom attributes in the
<bind> for the question (easily done with
pyxform and XLSForms). The result would be to have a bind such as:
<bind nodeset="/form/range_widget" startLabelCalculate="jr:choice-name( /form/start_label ,' /form/range_label_question ')" endLabelCalculate="jr:choice-name( /form/end_label ,' /form/range_label_question ')" type="int" />
end_label would refer to nodes with default string values. Those values would be choice names for a question
range_label_question so that we could handle translations. How can I obtain the attributes of the bind in the widget creation code? How can I evaluate the
For me it is OK that this is a hack-y approach. I just want to get this feature by editing ODK Collect.
By default, I could change the ODK Collect code to look up a string resource when creating the widget. I am hoping to have a solution like the above to allow the label to be set by the form designer.
You can get attribute values from the
FormEntryPrompt by calling the
getQuestion method and then calling
getAdditionalAttribute on the question. Search the code for
getAdditionalAttribute to see examples. I don't believe that the attribute value will have been evaluated but you should check that. If not, you can use
XPathParseTool.parseXPath to evaluate it.
I'm also interested in this topic. I would like to design a range widget with text instead of numbers at the ends of the range bar and without the label of the numeric value on top of the bar. So basically it would be a slider allowing respondents to indicate a 'preference' in between 2 text values (more of A, more of B or somewhere in between). This would give me as output a numeric value (without showing the label of this output on the screen).
Anyone here who could support me or share an example of their script? Thanks a lot in advance.
You could do a select with five options. The label of the first could be A, the fifth could be B, and the rest could be blank. Then use whatever numeric values you'd like. Then you could instruct the user to select where they are on that scale. It's sort of a likert scale.
There is a pr on the Javarosa's side https://github.com/opendatakit/javarosa/pull/258
but no progress for a long time. What do you think about that pr @yanokwa?
I think that PR has been sitting because it'll require spec changes.
Perhaps @Toon_Driesen can file a feature request at https://forum.getodk.org/c/features and we can loop the spec folks into the conversation. I'll post that on the PR and request that the poster do the same.
Thanks for your interest in this topic! I posted a feature request: Slider widget with text as begin and end label