Browse Source

Validate loan fields

master
Immanuel Onyeka 1 year ago
parent
commit
090ab9f565
4 changed files with 19 additions and 6 deletions
  1. +1
    -1
      assets/main.css
  2. +1
    -1
      components/login.vue
  3. +16
    -4
      components/new.vue
  4. +1
    -0
      skouter.go

+ 1
- 1
assets/main.css View File

@@ -86,7 +86,7 @@ menu.sidebar {
gap: 20px; gap: 20px;
} }


div.errors {
ul.errors {
color: var(--text-important); color: var(--text-important);
margin: 20px 0; margin: 20px 0;
min-height: 40px 0; min-height: 40px 0;


+ 1
- 1
components/login.vue View File

@@ -41,4 +41,4 @@ export default {
return { email: "", password: "", error: ""} return { email: "", password: "", error: ""}
}, },
} }
</script>
</script>

+ 16
- 4
components/new.vue View File

@@ -173,9 +173,9 @@ selected="estimate.transaction == 1">


<button @click="generate">Generate</button> <button @click="generate">Generate</button>


<div class="errors">
<span v-for="e in errors">{{e}}</span>
</div>
<ul class="errors">
<li v-for="e in errors">{{e}}</li>
</ul>


</section> </section>


@@ -283,7 +283,7 @@ function setLtv(e) {
loan.amount = (ltv / 100 * this.estimate.price).toFixed(2) loan.amount = (ltv / 100 * this.estimate.price).toFixed(2)
} }


// Changes loan.amount's <input> and data() values, then syncs with data.ltv
// Changes loan.amount\'s <input> and data() values, then syncs with data.ltv
function setAmount(e) { function setAmount(e) {
let amount = strip(e) let amount = strip(e)
let loan = this.loans[this.sel] let loan = this.loans[this.sel]
@@ -356,6 +356,18 @@ function validate() {
} else if (!estimate.mIncome) { } else if (!estimate.mIncome) {
errors.push("Missing monthly income.") errors.push("Missing monthly income.")
} }
estimate.loans.forEach(l => {
if (errors.length) return

if (!l.amount) {
errors.push("Loan amount cannot be zero")
} else if (!l.interest) {
errors.push("Interest rate cannot be zero")
} else if (!l.term) {
errors.push("Loan term cannot be zero")
}
})


return errors return errors
} }


+ 1
- 0
skouter.go View File

@@ -880,6 +880,7 @@ func api(w http.ResponseWriter, r *http.Request) {
panic(err) panic(err)
// maybe os.Exit(1) instead // maybe os.Exit(1) instead
} }
switch { switch {
case match(p, "/api/login", &args) && case match(p, "/api/login", &args) &&
r.Method == http.MethodPost: r.Method == http.MethodPost:


Loading…
Cancel
Save