Another flexibility feature that I love from PHPMaker is the ability to disable the element on the form by using Server Events. You can decide to disable the certain elements on the form that suits your needs or based on your business process for the certain pages. In other words, you don't need to modify any generated code/files, since we can manage it from the PHPMaker project side using Server Events feature.
This following trick will show you how to write such code in Server Events of PHPMaker for a ComboBox or Select Option control on the Edit pages. However, I will also show you how to implement it for the Add pages by using two ways/methods. By implementing this trick, then you will know about the most famous Server Events in PHPMaker you will most use in future: Row_Rendered. You will also learn about the Fields properties that related to disable or lock the elements on the form for Add and Edit pages.
[hidepost]
- Open your PHPMaker project (.pmp) file using PHPMaker application.
- Click on your desired table in the Database pane of PHPMaker.
-
Click on the Code (Server Events, Client Scripts and Custom Templates) tab at the right pane, go to Server Events -> Table-Specific -> Common -> Row_Rendered, and then insert the following code into the function in the code editor at the right pane of PHPMaker (make sure you insert the following code inside the Row_Rendered function):
if (CurrentPageID() == "edit") { $this->YourFieldName->Disabled = TRUE; // Don't forget to adjust "YourFieldName" with your desired field name }As you can see from the code above, Fields object in PHPMaker has the Disabled property which has the boolean type. The default value is FALSE. So, if you want to disable the Select box (Combobox) on the form, then simply assign the property with TRUE.
Please note that actually there is another property named ReadOnly which will lock or unlock the elements on the form. Unfortunately, we cannot use it for Select box since it will work for Text box element on the form.
-
Another trick that you can do is by using EditCustomAttributes property that belongs to the Fields object. You may use the following code which will act the same result with the previous code above:
if (CurrentPageID() == "edit") { $this->YourFieldName->EditCustomAttributes = "disabled='disabled'"; // Don't forget to adjust "YourFieldName" with your desired field name }As you can see that we can simply assign the EditCustomAttributes property with that string value above, since it will also turn the Select box become read-only or locked.
-
If you want to implement it also for Add pages, then simply change the following code:
if (CurrentPageID() == "edit") {become:
if (CurrentPageID() == "edit" || CurrentPageID() == "add") { - Finally, re-generate your script files using PHPMaker as always.
[/hidepost]
Leave a Reply
You must be logged in to post a comment.