Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

fix: numeric constraints and range values are numeric #31

Merged
merged 3 commits into from
Mar 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/convert.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion spec/src/convert-question-spec.ls
Original file line number Diff line number Diff line change
Expand Up @@ -545,4 +545,7 @@ describe 'parameters' ->
for appearance in [ 'Slider', 'Vertical Slider', 'Picker' ]
result = { type: \inputNumeric, appearance, selectRange: { min: 13, max: 42 }, selectStep: 1.5 } |> convert-simple
expect(result.parameters).toBe('start=13 end=42 step=1.5')

# Slider parameters are quoted in XForm but must be numeric in XLSForm
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new test shows the intended added behaviour: string values get cast to numeric.

for appearance in [ 'Slider', 'Vertical Slider', 'Picker' ]
result = { type: \inputNumeric, appearance, selectRange: { min: \13, max: \42 }, selectStep: \1.5 } |> convert-simple
expect(result.parameters).toBe('start=13 end=42 step=1.5')
2 changes: 1 addition & 1 deletion src/convert.ls
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ convert-question = (question, context, prefix = []) ->
# range parameters.
if question.type is \range
select-range = (delete question.selectRange)
question.parameters = { start: select-range?.min, end: select-range?.max, step: (delete question.selectStep) }
question.parameters = { start: +select-range?.min, end: +select-range?.max, step: +(delete question.selectStep) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The explicit cast to numeric is the main and only source code change of this PR.

question.appearance = range-appearance-conversion[delete question.appearance]
if question.sliderTicks is false
question.appearance = ((question.appearance ? '') + ' no-ticks').trim()
Expand Down