From e2cf14d10ac430124b8f4541040e5548614ecc76 Mon Sep 17 00:00:00 2001 From: Immanuel Onyeka Date: Mon, 7 Nov 2022 18:06:27 -0500 Subject: [PATCH] Add MI and HOA fields --- components/mi.vue | 5 ++ components/new.vue | 119 +++++++++++++++++++++++++-------------------- 2 files changed, 72 insertions(+), 52 deletions(-) create mode 100644 components/mi.vue diff --git a/components/mi.vue b/components/mi.vue new file mode 100644 index 0000000..17a6529 --- /dev/null +++ b/components/mi.vue @@ -0,0 +1,5 @@ + + + diff --git a/components/new.vue b/components/new.vue index f334c38..1a1a8e6 100644 --- a/components/new.vue +++ b/components/new.vue @@ -41,10 +41,10 @@ class="bi bi-plus" viewBox="0 0 16 16"> +@input="(e) => estimate.borrowers = stripInt(e)"> +@input="(e) => estimate.creditScore = stripInt(e)"> @@ -53,11 +53,11 @@ class="bi bi-plus" viewBox="0 0 16 16">

Transaction Type

- - @@ -109,46 +109,42 @@ selected="estimate.transaction == 1"> + + + - + - - - - - - - - - - - - - - - + + + + + + + + + + + -
-

Interest Rates

- - - - - - - - - - - - - - +
+

Mortgage Insurance

+ + + +
@@ -166,11 +162,10 @@ const example = { interest: 0, interestDays: 0, hazard: 0, // Hazard insurance monthly payment - hazardMonths: 0, // Hazard insurance months - hazardEscrowed: true, // If hazard insurance is escrowed + hazardEscrow: 0, // Hazard insurance escrow in months (0 is none) tax: 0, // Real Estate taxes monthly payment - taxEscrow: 0, // Months to escrow - taxEscrowed: true, // If tax is escrowed + taxEscrow: 0, // Months to escrow (0 is none) + hoa: 0, // Home owner's association monthly fee program: "", pud: true, // Property under development zip: '' @@ -196,13 +191,36 @@ function create() { this.estimate.loans.push(Object.assign({}, loans[0])) } -// Strips non-digits from an input box event and returns it's rounded integer +// Strips non-digits from an input box event and returns it's rounded integer. +// It also preserves current valid entry (.) function strip(e) { + let valid = e.target.value.match(/\d+\.?\d?\d?/)?.[0] ?? "" + e.target.value = valid + return Number(valid || 0) +} + +function stripInt(e) { let value = parseInt(e.target.value.replace(/\D/g, '') || 0) e.target.value = value return value } +function stripPerc(e) { + let num = strip(e) + + if (num > 100) { + num = 100 + e.target.value = num + } + + if (num < 0) { + num = 0 + e.target.value = num + } + + return num +} + function stripLetters(e) { let value = (e.target.value.replace(/[^\w\s]/g, '').slice(0, 20) || '') e.target.value = value @@ -227,8 +245,7 @@ function setLtv(e) { if (ltv < 0) ltv = 0 loan.ltv = ltv - e.target.value = ltv - loan.amount = Math.round(ltv / 100 * this.estimate.price) + loan.amount = (ltv / 100 * this.estimate.price).toFixed(2) } // Changes loan.amount's and data() values, then syncs with data.ltv @@ -241,15 +258,13 @@ function setAmount(e) { if (amount < 0) amount = 0 loan.amount = amount - e.target.value = amount - loan.ltv = Math.round(amount / this.estimate.price * 100) + loan.ltv = (amount / this.estimate.price * 100).toFixed(2) } // Updates the property price for all loans function setPrice(e) { let value = strip(e) this.estimate.price = value - e.target.value = value } function setDti(e) { @@ -278,8 +293,8 @@ function setHousingDti(e) { export default { methods: { - setPrice, setLtv, setAmount, setDti, setHousingDti, - strip, stripLetters, del, create + setPrice, setLtv, setAmount, setDti, setHousingDti, strip, stripInt, + stripLetters, stripPerc, del, create }, props: ['user'], data() {