Skip to content

Commit 0227f4c

Browse files
authored
gw-conditional-readonly.js: Fixed issue where value variable was not used and the condition was not evaluated on form render.
1 parent dc763b4 commit 0227f4c

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

gravity-forms/gw-conditional-readonly.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313
const value = "abc";
1414

1515
// Update "4" to the field to check for the conditional value.
16-
const $sourceField = document.getElementById("input_GFFORMID_1");
16+
const $sourceField = document.getElementById("input_GFFORMID_4");
1717

1818
// Update "5" to the field that should be marked as readonly if the conditional value is present.
19-
const $readOnlyField = document.getElementById("input_GFFORMID_3");
19+
const $readOnlyField = document.getElementById("input_GFFORMID_5");
2020

21+
// Evaluate once when the form is rendered.
22+
setFieldAsReadonlyConditionally();
23+
24+
// Evaluate again each time our source field receives input.
2125
$sourceField.addEventListener("input", function () {
22-
$readOnlyField.readOnly = $sourceField.value.toLowerCase() === "abc";
26+
setFieldAsReadonlyConditionally();
2327
});
28+
29+
function setFieldAsReadonlyConditionally() {
30+
$readOnlyField.readOnly = $sourceField.value.toLowerCase() === value;
31+
}

0 commit comments

Comments
 (0)