Skip to content

Instantly share code, notes, and snippets.

@saifsultanc
Created February 26, 2025 01:47
Show Gist options
  • Save saifsultanc/22c203d28cfb7d2c333f2da74b96830e to your computer and use it in GitHub Desktop.
Save saifsultanc/22c203d28cfb7d2c333f2da74b96830e to your computer and use it in GitHub Desktop.
gw-conditional-read-only.php
<?php
/**
* Gravity Wiz // Gravity Forms // Conditional Readonly Fields
* https://gravitywiz.com/
*
* This simple snippet will mark a field as readonly if a given source field has a specific value.
*
* Instructions:
*
* 1. Install this snippet with our free Code Chest plugin.
* https://gravitywiz.com/gravity-forms-code-chest/
*/
// Update "Non" to the conditional value that should be checked for in the source field.
const value = "non";
// Update "230" to the field to check for the conditional value.
const $sourceField = document.getElementById("input_GFFORMID_230");
// Update "3" to the field that should be marked as readonly if the conditional value is present.
const $readOnlyField = document.getElementById("input_GFFORMID_3");
// Evaluate once when the form is rendered.
setFieldAsReadonlyConditionally();
// Evaluate again each time our source field receives input.
$sourceField.addEventListener("input", function () {
setFieldAsReadonlyConditionally();
});
function setFieldAsReadonlyConditionally() {
$readOnlyField.readOnly = $sourceField.value.toLowerCase() === value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment