@dmitryvim/form-builder 0.2.13 → 0.2.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/formbuilder.min.js +42 -42
- package/dist/browser/{formbuilder.v0.2.13.min.js → formbuilder.v0.2.14.min.js} +42 -42
- package/dist/cjs/index.cjs +26 -34
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.js +26 -34
- package/dist/esm/index.js.map +1 -1
- package/dist/form-builder.js +42 -42
- package/package.json +1 -1
package/dist/esm/index.js
CHANGED
|
@@ -891,10 +891,10 @@ function updateTextareaField(element, fieldPath, value, context) {
|
|
|
891
891
|
}
|
|
892
892
|
|
|
893
893
|
// src/components/number.ts
|
|
894
|
-
function
|
|
895
|
-
const
|
|
896
|
-
|
|
897
|
-
|
|
894
|
+
function createNumberRangeHint(element, input) {
|
|
895
|
+
const hint = document.createElement("span");
|
|
896
|
+
hint.className = "number-range-hint";
|
|
897
|
+
hint.style.cssText = `
|
|
898
898
|
position: absolute;
|
|
899
899
|
top: 50%;
|
|
900
900
|
transform: translateY(-50%);
|
|
@@ -905,38 +905,30 @@ function createNumberCounter(element, input) {
|
|
|
905
905
|
background: var(--fb-background-color);
|
|
906
906
|
padding: 0 4px;
|
|
907
907
|
`;
|
|
908
|
-
const
|
|
908
|
+
const min = element.min;
|
|
909
|
+
const max = element.max;
|
|
910
|
+
let rangeText = "";
|
|
911
|
+
if (min != null && max != null) {
|
|
912
|
+
rangeText = `${min} \u2013 ${max}`;
|
|
913
|
+
} else if (max != null) {
|
|
914
|
+
rangeText = `\u2264${max}`;
|
|
915
|
+
} else if (min != null) {
|
|
916
|
+
rangeText = `\u2265${min}`;
|
|
917
|
+
}
|
|
918
|
+
hint.textContent = rangeText;
|
|
919
|
+
const updateColor = () => {
|
|
909
920
|
const val = input.value ? parseFloat(input.value) : null;
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
return;
|
|
915
|
-
}
|
|
916
|
-
if (val == null || min != null && val < min) {
|
|
917
|
-
if (min != null && max != null) {
|
|
918
|
-
counter.textContent = `${min}-${max}`;
|
|
919
|
-
} else if (max != null) {
|
|
920
|
-
counter.textContent = `\u2264${max}`;
|
|
921
|
-
} else if (min != null) {
|
|
922
|
-
counter.textContent = `\u2265${min}`;
|
|
923
|
-
}
|
|
924
|
-
counter.style.color = "var(--fb-text-secondary-color)";
|
|
925
|
-
} else if (max != null && val > max) {
|
|
926
|
-
counter.textContent = `${val}/${max}`;
|
|
927
|
-
counter.style.color = "var(--fb-error-color)";
|
|
921
|
+
if (val != null) {
|
|
922
|
+
const belowMin = min != null && val < min;
|
|
923
|
+
const aboveMax = max != null && val > max;
|
|
924
|
+
hint.style.color = belowMin || aboveMax ? "var(--fb-error-color)" : "var(--fb-text-secondary-color)";
|
|
928
925
|
} else {
|
|
929
|
-
|
|
930
|
-
counter.textContent = `${val}/${max}`;
|
|
931
|
-
} else {
|
|
932
|
-
counter.textContent = `${val}`;
|
|
933
|
-
}
|
|
934
|
-
counter.style.color = "var(--fb-text-secondary-color)";
|
|
926
|
+
hint.style.color = "var(--fb-text-secondary-color)";
|
|
935
927
|
}
|
|
936
928
|
};
|
|
937
|
-
input.addEventListener("input",
|
|
938
|
-
|
|
939
|
-
return
|
|
929
|
+
input.addEventListener("input", updateColor);
|
|
930
|
+
updateColor();
|
|
931
|
+
return hint;
|
|
940
932
|
}
|
|
941
933
|
function renderNumberElement(element, ctx, wrapper, pathKey) {
|
|
942
934
|
const state = ctx.state;
|
|
@@ -963,7 +955,7 @@ function renderNumberElement(element, ctx, wrapper, pathKey) {
|
|
|
963
955
|
}
|
|
964
956
|
inputWrapper.appendChild(numberInput);
|
|
965
957
|
if (!state.config.readonly && (element.min != null || element.max != null)) {
|
|
966
|
-
const counter =
|
|
958
|
+
const counter = createNumberRangeHint(element, numberInput);
|
|
967
959
|
inputWrapper.appendChild(counter);
|
|
968
960
|
}
|
|
969
961
|
wrapper.appendChild(inputWrapper);
|
|
@@ -1014,7 +1006,7 @@ function renderMultipleNumberElement(element, ctx, wrapper, pathKey) {
|
|
|
1014
1006
|
}
|
|
1015
1007
|
inputContainer.appendChild(numberInput);
|
|
1016
1008
|
if (!state.config.readonly && (element.min != null || element.max != null)) {
|
|
1017
|
-
const counter =
|
|
1009
|
+
const counter = createNumberRangeHint(element, numberInput);
|
|
1018
1010
|
inputContainer.appendChild(counter);
|
|
1019
1011
|
}
|
|
1020
1012
|
itemWrapper.appendChild(inputContainer);
|