Skip to content

Change the color of input column depending on the selected content

Answer

Use "Script".


Overview

Using a "Script", you can change the color of input fields according to the value selected in a class column.

Operation Procedure

  1. Create a record table.
  2. On the "Manage table" screen, enable "ClassA", "Value A", and "Value B".
  3. Create a new "Script" and enter the following sample code.
    For "Output to", select "Create new" and "Edit".

    Output to: Create new and Edit
    $(document).on('change', '#' + $p.getControl('ClassA')[0].id, function() {
        const myClassA = $p.getControl('ClassA').val();
        const myCssBlue = {'borderColor': 'blue', 'background': '#f0f8ff'};
        const myCssDefault = {'borderColor': '#c0c0c0', 'background': 'white'};
        switch(myClassA) {
            case 'A':
                // Processing for number A
                $p.getControl('NumA').css(myCssBlue);
                // Processing for number B
                $p.getControl('NumB').css(myCssDefault);
                break;
            case 'B':
                // Processing for number B
                $p.getControl('NumB').css(myCssBlue);
                // Processing for number A
                $p.getControl('NumA').css(myCssDefault);
                break;
            default:
                // Processing for number A
                $p.getControl('NumA').css(myCssDefault);
                // Processing for number B
                $p.getControl('NumB').css(myCssDefault);
                break;
        }
    });
    
  4. Click the "Update" button in the command button area.

Execution Result

The colors of "Value A" and "Value B" change as follows depending on the selection in "ClassA".

The color of "Value A" changes to blue.

The numA field with a blue border after "A" is selected in ClassA

The color of "Value B" changes to blue.

The numB field with a blue border after "B" is selected in ClassA

The colors of "Value A" and "Value B" return to their original state.

The numA and numB fields with their original border colors restored