Disable Fields - Logic 1.7.24 Bootstrap 4.5 theme
Hide fields based on an input or selected logic. For this instance selecting status "Shipped" will disable Requireddate and Shippeddate
HIDE CODE
<?php // Get an instance of the Xcrud class $xcrud = Xcrud::get_instance(); // Set the table to work with $xcrud->table("orders"); // Define which columns to display in the table $xcrud->columns("orderDate,status,requiredDate,shippedDate,comments"); // Define which fields are available for data entry or editing $xcrud->fields("orderDate,status,requiredDate,shippedDate,comments"); $xcrud->change_type("orderDate","flatpickr","","{enableTime:false,dateFormat:Y-m-d H:i:s,locale:it,altFormat:d-m-Y,altInput: true}");//"{enableTime:true,dateFormat:Y-m-d H:i:s,locale:it,altFormat:d-m-Y H:i:s,altInput: true} $xcrud->change_type("requiredDate","flatpickr","",'{enableTime:false,dateFormat:Y-m-d H:i,locale:it,altFormat:d-m-Y,altInput: true}'); //$xcrud->change_type("shippedDate","flatpickr","",'{enableTime:true,dateFormat:Y-m-d H:i,locale:it,altFormat:d-m-Y,altInput: true}'); // Change the input type of the 'status' field to a select dropdown and provide options $xcrud->change_type("status","select","",array("Not Shipped"=>"Not Shipped","Shipped"=>"Shipped","Completed"=>"Completed")); // Disable the 'requiredDate' field when the 'status' is 'Shipped' $xcrud->disable_logic("requiredDate","status","=","Shipped"); // Disable the 'shippedDate' field when the 'status' is 'Shipped' $xcrud->disable_logic("shippedDate","status","=","Shipped"); // Render the xcrud instance to display the table and form echo $xcrud->render(); ?>
Orders
# | Orderdate | Status | Requireddate | Shippeddate | Comments | |
---|---|---|---|---|---|---|
1 | 2003-06-27 00:00:00 | Shipped | 2003-07-04 00:00:00 | 03.07.2003 00:00:00 | NULL | View Edit Remove |
2 | 2003-07-01 00:00:00 | Shipped | 2003-07-10 00:00:00 | 05.07.2003 00:00:00 | View Edit Remove | |
3 | 2003-07-02 00:00:00 | Shipped | 2003-07-12 00:00:00 | 03.07.2003 00:00:00 | NULL | View Edit Remove |
4 | 2003-07-04 00:00:00 | Shipped | 2003-07-14 00:00:00 | 06.07.2003 00:00:00 | Customer is interested in buying more Ferrari | View Edit Remove |
5 | 2003-07-10 00:00:00 | Shipped | 2003-07-20 00:00:00 | 15.05.2024 00:00:00 | PROVA | View Edit Remove |
6 | 2003-07-07 00:00:00 | Shipped | 2003-07-16 00:00:00 | 13.07.2003 00:00:00 | View Edit Remove | |
7 | 2003-07-16 00:00:00 | Shipped | 2003-07-23 00:00:00 | 21.07.2003 00:00:00 | View Edit Remove | |
8 | 2003-07-24 00:00:00 | Shipped | 2003-08-02 00:00:00 | 30.07.2003 00:00:00 | View Edit Remove | |
9 | 2003-08-01 00:00:00 | Shipped | 2003-08-09 00:00:00 | 04.08.2003 00:00:00 | View Edit Remove | |
10 | 2003-08-08 00:00:00 | Shipped | 2003-08-16 00:00:00 | 13.08.2003 00:00:00 | View Edit Remove |