class TestVerifyForm { constructor() { this.$invoiceAmountField = $("#invoice-amount"); this.$newTestIsRetestField = $("#new-test-is-retest"); this.$newTestIsRetestField.on("change", event => this.updateInvoiceAmount()); this.$newTestProjectField = $("#new-test-project-id"); this.$newTestProjectField.on("change", event => this.updateInvoiceAmount()); this.$paymentRequiredField = $("#payment-required"); this.$paymentRequiredField.on("change", event => { $("#invoice-amount").closest(".row").prop("hidden", !event.currentTarget.checked); }); } updateInvoiceAmount() { const $option = this.$newTestProjectField.find("option:selected"); let customerFee = $option.attr("data-customer-fee"); if(this.$newTestIsRetestField.prop("checked")) { customerFee = $option.attr("data-retest-fee"); } this.$invoiceAmountField.val(customerFee); } } $(() => new TestVerifyForm());