fix(master-rule): add validation cf value
This commit is contained in:
parent
90c4d8bd94
commit
b15e0486f2
|
@ -1,25 +1,85 @@
|
|||
var checkAll = document.getElementById("checkAll");
|
||||
checkAll &&
|
||||
(checkAll.onclick = function () {
|
||||
for (
|
||||
var e = document.querySelectorAll(
|
||||
'.form-check-all input[type="checkbox"]'
|
||||
),
|
||||
t = 0;
|
||||
t < e.length;
|
||||
t++
|
||||
)
|
||||
(e[t].checked = this.checked),
|
||||
e[t].checked
|
||||
? e[t].closest("tr").classList.add("table-active")
|
||||
: e[t].closest("tr").classList.remove("table-active");
|
||||
});
|
||||
document.addEventListener("DOMContentLoaded", function () {
|
||||
const indicatorField = document.getElementById("indicator-field");
|
||||
const indicatorVal = new Choices(indicatorField);
|
||||
const indicatorEditField = document.getElementById("indicator-edit-field");
|
||||
window.indicatorEditVal = new Choices(indicatorEditField);
|
||||
});
|
||||
|
||||
function updateData(rule) {
|
||||
var form = document.getElementById("edit-form");
|
||||
var categoryEditField = form.querySelector("#category-edit-field");
|
||||
var description = form.querySelector("#description-edit-field");
|
||||
var cf = form.querySelector("#cf-edit-field");
|
||||
form.action = "/data-aturan/" + rule.id;
|
||||
|
||||
window.indicatorEditVal.setChoiceByValue(rule.indicator_id.toString());
|
||||
window.indicatorEditVal.passedElement.element.value =
|
||||
rule.indicator_id.toString();
|
||||
categoryEditField.value = rule.parameter_type;
|
||||
description.value = rule.description;
|
||||
cf.value = rule.cf;
|
||||
}
|
||||
|
||||
function deleteData(id) {
|
||||
var form = document.getElementById("delete-form");
|
||||
form.action = "/data-aturan/" + id;
|
||||
}
|
||||
|
||||
function validateCfInput(input) {
|
||||
input.value = input.value.replace(",", ".");
|
||||
|
||||
input.value = input.value.replace(/[^0-9.\-]/g, "");
|
||||
|
||||
if (input.value.includes("-") && !input.value.startsWith("-")) {
|
||||
input.value = input.value.replace("-", "");
|
||||
}
|
||||
|
||||
input.value = input.value.replace(/-+/g, "-");
|
||||
|
||||
if (input.value === "-") {
|
||||
return;
|
||||
}
|
||||
|
||||
if (input.value.startsWith(".")) {
|
||||
input.value = "0" + input.value;
|
||||
}
|
||||
|
||||
if (input.value.startsWith("-.")) {
|
||||
input.value = "-0.";
|
||||
}
|
||||
|
||||
// **PERBAIKAN**: Hilangkan nol berlebih di depan angka, kecuali nol sebelum titik
|
||||
input.value = input.value.replace(/^(-?)0+(\d)/, "$1$2");
|
||||
|
||||
// **BATASI INPUT**: Hanya satu titik desimal, dan maksimal 1 angka setelah titik
|
||||
let match = input.value.match(/^-?\d*(\.\d{0,1})?/);
|
||||
if (match) {
|
||||
input.value = match[0];
|
||||
}
|
||||
|
||||
let numValue = parseFloat(input.value);
|
||||
|
||||
if (!isNaN(numValue)) {
|
||||
let decimal = Math.abs(numValue * 10);
|
||||
let lastDigit = decimal % 10;
|
||||
|
||||
if (lastDigit % 2 === 1) {
|
||||
input.value = "";
|
||||
alert("Nilai CF Tidak Sesuai");
|
||||
return;
|
||||
}
|
||||
|
||||
// **Batasi nilai antara -1.0 dan 1.0**
|
||||
if (!isNaN(numValue)) {
|
||||
if (numValue > 1) {
|
||||
input.value = "1.0";
|
||||
} else if (numValue < -1) {
|
||||
input.value = "-1.0";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var perPage = 10,
|
||||
options = {
|
||||
valueNames: ["id", "customer_name", "email", "date", "phone", "status"],
|
||||
|
@ -130,7 +190,7 @@ refreshCallbacks(),
|
|||
(document.getElementById("edit-btn").style.display = "block"))
|
||||
: e.relatedTarget.classList.contains("add-btn")
|
||||
? ((document.getElementById("exampleModalLabel").innerHTML =
|
||||
"Add Customer"),
|
||||
"Tambah Data Aturan"),
|
||||
(document
|
||||
.getElementById("showModal")
|
||||
.querySelector(".modal-footer").style.display = "block"),
|
||||
|
|
|
@ -50,7 +50,7 @@ class="ri-add-line align-bottom me-1"></i> Tambah</button>
|
|||
<th class="sort" data-sort="customer_name">Indikator</th>
|
||||
<th class="sort" data-sort="email">Kategori</th>
|
||||
<th class="sort" data-sort="phone">Deskripsi</th>
|
||||
<th class="sort" data-sort="status">CF(e)</th>
|
||||
<th class="sort" data-sort="status">Nilai CF</th>
|
||||
<th class="sort" data-sort="action">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -174,7 +174,7 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<label for="cf-field" class="form-label">CF(e)</label>
|
||||
<label for="cf-field" class="form-label">Nilai CF</label>
|
||||
<input type="text" id="cf-field" class="form-control" name="cf"
|
||||
placeholder="Masukan nilai CF pakar" required oninput="validateCfInput(this)" />
|
||||
<div class="invalid-feedback">
|
||||
|
@ -246,11 +246,11 @@ class="fw-medium link-primary">#VZ2101</a></td>
|
|||
</div>
|
||||
|
||||
<div>
|
||||
<label for="cf-edit-field" class="form-label">CF(e)</label>
|
||||
<label for="cf-edit-field" class="form-label">Nilai CF</label>
|
||||
<input type="text" id="cf-edit-field" class="form-control" name="cf"
|
||||
placeholder="Masukan Nilai CF(e)" required oninput="validateCfInput(this)" />
|
||||
placeholder="Masukan Nilai Nilai CF" required oninput="validateCfInput(this)" />
|
||||
<div class="invalid-feedback">
|
||||
Masukan CF(e)
|
||||
Masukan Nilai CF
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
Loading…
Reference in New Issue