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

Conversation

florianm
Copy link
Contributor

@florianm florianm commented Feb 19, 2022

  • livescript is terse, but at least the numeric cast operator is a big plus
  • convert-question for type "range" casts min, max, step to numeric
  • no extensive testing done yet with different ranges
  • tested: numeric question with appearance slider > XLSForm > Central > Collect works
  • tested: numeric question with valid range > XLSForm > Central > Collect works
  • Fix Numeric slider range parameters start, end, step should be numeric, not string #20

update:

  • constraints work even if the values are strings - won't cast them
  • add tests to verify that range parameters given as string are getting converted to int

* livescript is terse, but at least the numeric cast operator is a big plus
* expr-value casts to numeric (do we expect dates or types other than string and numeric here?)
* convert-question for type "range" casts min, max, step to numeric
* no extensive testing done yet with different ranges and constraints
* existing tests passing, no new tests added (coming next)
* tested: numeric question with appearance slider > XLSForm > Central > Collect works
* tested: numeric question with valid range > XLSForm > Central > Collect works
@florianm florianm added the bug label Feb 19, 2022
@florianm florianm added this to the 1.7 milestone Feb 19, 2022
@florianm florianm self-assigned this Feb 19, 2022
* Constraints work even if the values are strings
* Add tests for range parameters given as string getting converted to int
@@ -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.

@@ -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.

@@ -228,7 +228,7 @@ describe \constraint ->

test 'build number range constraint generation (max)' ->
result = { type: \inputNumber, range: { max: 3, maxInclusive: true } } |> convert-simple
expect(result.constraint).toBe('(. <= 3)')
expect(result.constraint).toBe('(. <= 3)')
Copy link
Contributor Author

Choose a reason for hiding this comment

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

That extra whitespace is a dud, sorry.

Copy link
Member

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

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

This was simpler than it looked on my phone. Remove the extra spaces before merging?

@florianm
Copy link
Contributor Author

Of course - there's always space for improvement.

@florianm florianm merged commit af3401a into getodk:master Mar 10, 2022
@florianm florianm deleted the 20-range branch March 10, 2022 22:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Numeric slider range parameters start, end, step should be numeric, not string
2 participants