Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

marionbarker
Copy link
Contributor

Purpose

Fix for Loop Issue 2307.

Method

I asked for help on solving this and got a suggestion from @bjorkert (thanks).

Once the file that needed to be modified was identified, I checked the status of that file in the tidepool-merge branch, LoopKit/LoopKitUI/CarbKit/CarbQuantityRow.swift

  • The file has been updated, so I started with the tidepool-merge version
    • The bug still happens with that version of the file
  • I modified the suggestion from @bjorkert to work with the tidepool-merge version
  • I configured a minAllowedCarbEntry of 1.0 (instead of using hard-coded 1.0) and required the entry be >= minAllowedCarbEntry before the continue button is enabled

I'm happy to modify this as desired.

Test

This fixes the reported bug:

  • A user can no longer type ".", "0", "5" and wind up with 5 g of carbs
  • The entered value must be >= 1 before the user can continue
  • If a value < 1 is entered, the continue button is inactive

@marionbarker marionbarker changed the title use tidepool-merge version, then fix carb entry bug, Issue 2307 Fix carb entry bug, Issue 2307 Apr 11, 2025
@marionbarker marionbarker requested a review from ps2 April 11, 2025 20:36
@bjorkert
Copy link
Contributor

This version does not allow "," as decimal separator. If I enter "0,5", I get "5".

@marionbarker
Copy link
Contributor Author

I tested this with 2 phones. One set for "." as a decimal separator and one for "," as a decimal separator.

It does prevent the case of ",05" or ".05" being interpreted as "5" g for both types of separators.

There is a difference in behavior depending on the separator:

  • for "," as decimalSeparator: the continue button is disabled for any entry that includes a ","
    • In other words, 10 will be accepted, "10," will not
  • for "." as decimalSeparator: the continue button is enabled for any entry >= 1 whether decimal place is included
    • In other words, 10.5 is accepted and displays as 10, 10.9 becomes 11

Copy link
Collaborator

@ps2 ps2 left a comment

Choose a reason for hiding this comment

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

Not great from a locale-supporting standpoint, but I see the separatory is covered.

if let number = formatter.number(from: input) {
quantity = number.doubleValue
let decimalSeparator = formatter.decimalSeparator ?? "."
let allowedCharacters = "0123456789" + decimalSeparator
Copy link
Collaborator

Choose a reason for hiding this comment

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

Has anyone tested that this works for arabic/persian locales?

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.

3 participants