Skip to content

fix(#749): handle negative step values#802

Merged
garethbowen merged 4 commits into
mainfrom
749-absolute-value-step
May 6, 2026
Merged

fix(#749): handle negative step values#802
garethbowen merged 4 commits into
mainfrom
749-absolute-value-step

Conversation

@garethbowen
Copy link
Copy Markdown
Collaborator

@garethbowen garethbowen commented May 6, 2026

Closes #749

I have verified this PR works in these browsers (latest versions):

  • Chrome
  • Firefox
  • Safari (macOS)
  • Safari (iOS)
  • Chrome for Android
  • Not applicable

What else has been done to verify that this works as intended?

Test written

Why is this the best possible solution? Were any other approaches considered?

This would've been much easier to do in the vue component but because it's a spec feature I think it's better to have it in the engine for all clients to benefit from.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

Do we need any specific form for testing your changes? If so, please attach one.

<h:html xmlns="http://www.w3.org/2002/xforms"
  xmlns:h="http://www.w3.org/1999/xhtml">

  <h:head>
    <h:title>Range controls</h:title>
    <model>
      <instance>
        <root id="range-controls">
          <range-decimal>1.0</range-decimal>
          <range-int>2</range-int>

          <vertical>
            <v-decimal>1.25</v-decimal>
            <v-int>1</v-int>
          </vertical>
        </root>
      </instance>
      <bind nodeset="/root/range-decimal" type="xsd:decimal" />
      <bind nodeset="/root/range-int" type="int" />
      <bind nodeset="/root/vertical/v-decimal" type="decimal" />
      <bind nodeset="/root/vertical/v-int" type="xsd:int" />
    </model>
  </h:head>

  <h:body>
    <range ref="/root/range-decimal" start="-2.0" end="2.0" step="-0.5">
      <label>Range control (decimal)</label>
    </range>
    <range ref="/root/range-int" start="-6" end="4" step="-2">
      <label>Range control (int)</label>
    </range>

    <group ref="/root/vertical">
      <range ref="/root/vertical/v-decimal" start="-5.0" end="7.0" step="-0.5"
        appearance="vertical">
        <label>Range control (decimal)</label>
      </range>
      <range ref="/root/vertical/v-int" start="-3" end="4" step="-3" appearance="vertical no-ticks">
        <label>Range control (int)</label>
      </range>
    </group>
  </h:body>

</h:html>

What's changed

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

🦋 Changeset detected

Latest commit: 2183dc2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@getodk/xforms-engine Patch
@getodk/common Patch
@getodk/xpath Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@garethbowen garethbowen requested a review from latin-panda May 6, 2026 03:46
Copy link
Copy Markdown
Collaborator

@latin-panda latin-panda left a comment

Choose a reason for hiding this comment

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

One small comment below, but approving now to unblock

@latin-panda
Copy link
Copy Markdown
Collaborator

latin-panda commented May 6, 2026

I couldn't comment inline 🤷🏽‍♀️ pasting it here instead:

Line 87: The flag looks odd to me. I'd prefer parsing here.

		const step = parseNumericStringAttribute(element, 'step');
		const absStep = (step.startsWith('-') ? step.substring(1) : step) as NumericString; 

return new this(start, end, absStep);

@garethbowen
Copy link
Copy Markdown
Collaborator Author

The flag looks odd to me. I'd prefer parsing here.

Yeah me too... but I also didn't like the cast. I've created a second function, which calls the assertion after the - has been split off which feels safer to me.

@garethbowen garethbowen merged commit b7927b1 into main May 6, 2026
50 checks passed
@garethbowen garethbowen deleted the 749-absolute-value-step branch May 6, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use absolute value of range step attribute value

2 participants