Skip to content

Commit

Permalink
Merge pull request #50 from sampocs/pochyly
Browse files Browse the repository at this point in the history
decimal issue
  • Loading branch information
sampocs authored Apr 26, 2019
2 parents 2ff6991 + c3d0169 commit b7887b4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 13 additions & 3 deletions screens/AddHabitScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,13 @@ class AddHabitScreen extends React.Component {
habitSettings.type = Constants.PROGRESS
habitSettings.habitInfo = {
unit: this.state.unit,
goal: this.state.goal === '.' ? 0 : parseInt(this.state.goal)
goal: this.state.goal.indexOf('.') === 0 ? 0 : parseInt(this.state.goal)
}

habitHistory.type = Constants.PROGRESS
habitHistory.habitInfo = {
progress: 0,
goal: this.state.goal === '.' ? 0 : parseInt(this.state.goal)
goal: this.state.goal.indexOf('.') === 0 ? 0 : parseInt(this.state.goal)
}
}
else if (this.state.includeSubtasksChecked) {
Expand Down Expand Up @@ -180,7 +180,8 @@ class AddHabitScreen extends React.Component {
}
return false
}
if (this.state.includeMeasurementsChecked && (this.state.goal === '' || this.state.goal === '.')) {
if (this.state.includeMeasurementsChecked &&
(this.state.goal === '' || this.state.goal === '.' || this.state.goal.indexOf('.') === 0)) {
if (alertUser) {
AlertIOS.alert(
'',
Expand All @@ -189,6 +190,15 @@ class AddHabitScreen extends React.Component {
}
return false
}
if (this.state.includeMeasurementsChecked && this.state.goal.replace(/[^.]/g, "").length > 1) {
if (alertUser) {
AlertIOS.alert(
'',
'Please enter a valid goal amount!'
)
}
return false
}
if (this.state.includeSubtasksChecked && this.state.subtasks.length === 0) {
if (alertUser) {
AlertIOS.alert(
Expand Down
16 changes: 13 additions & 3 deletions screens/EditHabitScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,13 @@ class EditHabitScreen extends React.Component {
habitSettings.type = Constants.PROGRESS
habitSettings.habitInfo = {
unit: this.state.unit,
goal: this.state.goal === '.' ? 0 : parseInt(this.state.goal)
goal: this.state.goal.indexOf('.') === 0 ? 0 : parseInt(this.state.goal)
}

habitHistory.type = Constants.PROGRESS
habitHistory.habitInfo = {
progress: 0,
goal: this.state.goal === '.' ? 0 : parseInt(this.state.goal)
goal: this.state.goal.indexOf('.') === 0 ? 0 : parseInt(this.state.goal)
}
}
else if (this.state.includeSubtasksChecked) {
Expand Down Expand Up @@ -187,7 +187,8 @@ class EditHabitScreen extends React.Component {
}
return false
}
if (this.state.includeMeasurementsChecked && (this.state.goal === '' || this.state.goal === '.')) {
if (this.state.includeMeasurementsChecked &&
(this.state.goal === '' || this.state.goal === '.' || this.state.goal.indexOf('.') === 0)) {
if (alertUser) {
AlertIOS.alert(
'',
Expand All @@ -196,6 +197,15 @@ class EditHabitScreen extends React.Component {
}
return false
}
if (this.state.includeMeasurementsChecked && this.state.goal.replace(/[^.]/g, "").length > 1) {
if (alertUser) {
AlertIOS.alert(
'',
'Please enter a valid goal amount!'
)
}
return false
}
if (this.state.includeSubtasksChecked && this.state.subtasks.length === 0) {
if (alertUser) {
AlertIOS.alert(
Expand Down

0 comments on commit b7887b4

Please sign in to comment.