How to disable the DropDown and "Allow Add"?

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
mpol_ch
User
Posts: 896
Location: Switzerland

How to disable the DropDown and "Allow Add"?

Post by mpol_ch »

Hi I am using the bellow code to disable the field "Kostenstelle"
This is working fine.

But the the field is a select modal dialog lookup field and has + button (allow Add) too.
How can I also disallow the options?
Right now the field is disabled but the suer can still have the modal lookup and add a new record into lookup table.
Any idea where to start?

    // Page_Load event
    function Page_Load() {
        // Get the current value of 'Kostenstelle'
        $currentKostenstelle = $this->Kostenstelle->CurrentValue;
    
        // Check if 'Kostenstelle' is not null or empty
        if ($currentKostenstelle !== null && $currentKostenstelle !== '') {
            // Query the database to get the 'ks_gueltig' value for the given 'Kostenstelle'
            $ks_gueltig = ExecuteScalar("SELECT ks_gueltig FROM kostenstelle WHERE ksid = " . $currentKostenstelle);
    
            // If 'ks_gueltig' is 0, disable the 'Kostenstelle' field on the Edit page
            if ($ks_gueltig == 0) {
                $this->Kostenstelle->EditAttrs["disabled"] = "disabled";
            }
        }
    }

mpol_ch


sangnandar
User
Posts: 1031

Post by sangnandar »

Check the generated code to see if there's object that can be used to not render + button.
If there aren't any, my suggestion is to do double-column.
That is create 2 columns in your table:

  • Kostenstelle, the real column
  • dummyKostenstelle, the fake column

You need to do that in database (alter view).

In Edit page

if (condition) {
  $this->Kostenstelle->Visible = false;
  $this->dummyKostenstelle->Visible = true; // or better check Readonly in Field Setup
}

Also adjust your logic in Row_Updating()

unset($rsnew["dummyKostenstelle"]); // prevent the field to be fired to db

Post Reply