Grey one field according to another

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
pasbonte
Veteran Member
Posts: 162
Joined: 2013-02-06 09:49

Grey one field according to another

Post by pasbonte » 2023-10-22 09:55

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

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1638
Joined: 2018-04-01 10:12

Re: Grey one field according to another

Post by pbottcher » 2023-10-22 16:13

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>
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

Post Reply