Skip to content

Commit

Permalink
Ignore invalid inputs to the treatments textfields to ensure that the…
Browse files Browse the repository at this point in the history
… original treatment isn't just deleted
  • Loading branch information
paulplant committed Apr 30, 2022
1 parent e7f0b9e commit e946889
Showing 1 changed file with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,25 @@ class TreatmentsInsertViewController : UIViewController {
UserDefaults.standard.nightScoutSyncTreatmentsRequired = true

}

} else {

// text is nil or "0", set treatmentdeleted to true
treatMentEntryToUpdate.treatmentdeleted = true
} else {

// set uploaded to false so that the entry is synced with NightScout
treatMentEntryToUpdate.uploaded = false

// trigger nightscoutsync
UserDefaults.standard.nightScoutSyncTreatmentsRequired = true
// even though there is not a valid/useable number entered, only delete the treatment if the user has really changed it to zero. If they didn't enter zero then just disregard the input.
if let text = textField.text, let value = Double(text.replacingOccurrences(of: ",", with: ".")), value == 0 {

// text is nil or "0", set treatmentdeleted to true
treatMentEntryToUpdate.treatmentdeleted = true

// set uploaded to false so that the entry is synced with NightScout
treatMentEntryToUpdate.uploaded = false

// trigger nightscoutsync
UserDefaults.standard.nightScoutSyncTreatmentsRequired = true

self.treatMentEntryToUpdate = nil

}

self.treatMentEntryToUpdate = nil

}

}
Expand Down

0 comments on commit e946889

Please sign in to comment.