changed price format
This commit is contained in:
@@ -1,5 +1,16 @@
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
document.querySelectorAll(".price-input").forEach((input) => {
|
||||
initPriceInputs(document);
|
||||
|
||||
document.addEventListener("formset:added", (event) => {
|
||||
initPriceInputs(event.target);
|
||||
});
|
||||
});
|
||||
|
||||
function initPriceInputs(root) {
|
||||
root.querySelectorAll(".price-input").forEach((input) => {
|
||||
if (input.dataset.formatted) return;
|
||||
input.dataset.formatted = "true";
|
||||
|
||||
input.value = format(input.value);
|
||||
|
||||
input.addEventListener("input", () => {
|
||||
@@ -8,13 +19,14 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
input.value = format(raw);
|
||||
input.setSelectionRange(cursor, cursor);
|
||||
});
|
||||
input.form.addEventListener("submit", () => {
|
||||
|
||||
input.form?.addEventListener("submit", () => {
|
||||
input.value = input.value.replace(/,/g, "");
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const format = (value) => {
|
||||
function format(value) {
|
||||
if (!value) return "";
|
||||
return value.replace(/\D/g, "").replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user