Page 1 of 1

Grey one field according to another

Posted: 2023-10-22 09:55
by pasbonte
Hello

I have two fields A and B I want to grey out field B when field A is entered and the opposite, do you know how to do it?

Thank you

Re: Grey one field according to another

Posted: 2023-10-22 16:13
by pbottcher
Hi,

as this is very specific the answer can not be clear.

What kind of fields do you have?
If you say gray out, does it mean that you want to make that field read-only?

in general, with javascript (jquery) you can a "on change" event on you fields and react accordingly, e.g.

Code: Select all

        $j(document).ready(function() {
            $j("#fieldA").on("input", function() {
                if (j$(this).val().trim() !== "") {
                    $j("#fieldB").prop("disabled", true).addClass("greyed-out");
                } else {
                    $j("#fieldB").prop("disabled", false).removeClass("greyed-out");
                }
            });

            $j("#fieldB").on("input", function() {
                if ($j(this).val().trim() !== "") {
                    $j("#fieldA").prop("disabled", true).addClass("greyed-out");
                } else {
                    $j("#fieldA").prop("disabled", false).removeClass("greyed-out");
                }
            });
        });
Add you style

Code: Select all

    <style>
        .greyed-out {
            background-color: #eee;
            pointer-events: none;
        }
    </style>