Skip to content

Commit

Permalink
Fix validation
Browse files Browse the repository at this point in the history
  • Loading branch information
gurbindersingh committed Nov 17, 2024
1 parent 851215b commit 52c1c2f
Showing 1 changed file with 30 additions and 10 deletions.
40 changes: 30 additions & 10 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,19 @@ const inputs: Inputs[] = [
isPercentage: false,
settingsKey: "currentAge",
id: "current-age",
isValid: () => settings.currentAge <= settings.retirementAge,
isValid: () =>
settings.currentAge <= settings.retirementAge &&
settings.currentAge < settings.lifeExpectancy,
min: 0,
max: 100,
steps: 1
steps: 1,
runOnChange: () => {
inputs
.filter((input) =>
["retirement-age", "life-expectancy"].includes(input.id)
)
.forEach((input) => toggleInputErrorHints(input.id, input.isValid()));
}
},
{
label: "Retirement Age",
Expand All @@ -42,7 +51,12 @@ const inputs: Inputs[] = [
isValid: () => settings.retirementAge < settings.lifeExpectancy,
min: 0,
max: 100,
steps: 1
steps: 1,
runOnChange: () => {
inputs
.filter((input) => ["current-age", "life-expectancy"].includes(input.id))
.forEach((input) => toggleInputErrorHints(input.id, input.isValid()));
}
},
{
label: "Life Expectancy",
Expand All @@ -51,10 +65,17 @@ const inputs: Inputs[] = [
isPercentage: false,
settingsKey: "lifeExpectancy",
id: "life-expectancy",
isValid: () => settings.retirementAge < settings.lifeExpectancy,
isValid: () =>
settings.retirementAge < settings.lifeExpectancy &&
settings.currentAge < settings.lifeExpectancy,
min: 0,
max: 100,
steps: 1
steps: 1,
runOnChange: () => {
inputs
.filter((input) => ["current-age", "retirement-age"].includes(input.id))
.forEach((input) => toggleInputErrorHints(input.id, input.isValid()));
}
},
{
label: "Annual Net Salary",
Expand Down Expand Up @@ -126,18 +147,17 @@ const inputs: Inputs[] = [
<span id="absolut-savings-contributions" class="mx-1">
${(
(100 * settings.monthlySavings) /
(settings.netSalary / 12)
(settings.netSalary / 12)
).toFixed(1)}
</span>
%
</span>
</p>`,
runOnChange: () => {
// Update the percentage display
document.getElementById(
"absolut-savings-contributions"
)!.innerHTML = `${(
(100 * settings.monthlySavings) / (settings.netSalary / 12)
document.getElementById("absolut-savings-contributions")!.innerHTML = `${(
(100 * settings.monthlySavings) /
(settings.netSalary / 12)
).toFixed(1)}`;
}
},
Expand Down

0 comments on commit 52c1c2f

Please sign in to comment.