This PHPMaker 2024 project will show you how to dynamically handle field from Read-Only to writable in Edit Page. It will also show you how the difference between ReadOnly and Disabled property of the field.
In Table 1, when you edit one of the records that has Status = No from the List page, then you will see the Description field is Read-Only, so that it cannot be edited on initial condition.
When the value in Allow Save is No, and we try to save the current record on Edit Page, then system will trigger an Error message which tells us, that we have to change Allow Save to Yes.
When that error happened, then the Description field becomes writable (not Read-Only anymore). And that is the interesting part of this logic. How we can make a field from Read-Only becomes writable dynamically.
Back to process, in order to allow to save the record, then we need to select Yes from Allow Save field. This will tell system to proceed to next process: save the current record after clicking one Save button.
In Table 2, we can make the fields become Read Only by using Row_Rendered server event only. However, we need to write a few lines of code in Row_Inserting and Row_Updating server events.
In Table 3, we can make the fields become Disabled by using Row_Rendered server event. Similarly, we need to write a few lines of code in Row_Inserting and Row_Updating server events, especially to prevent the old value from being vanished.
Please note that, if we do not handle the default value in Disabled field by using Row_Inserting and/or Row_Updating server event, then the existing value will be vanished, since the disabled field will not be submitted by the form.
By using this project, then we will learn:
- How to set a Field from Read-Only to Writable dynamically in Edit Page when the form is loaded.
- How to create CSS code from HTML -> Styles -> User in order to make different style for Read-Only field.
- How to use Row_Rendered server event in order to set initial status for Read-Only field.
- How to use Page_Render server event in order to set truly Read-Only for a field based on certain condition.
- How to use Row_Updating server event to prevent save record, and remove Read-Only condition for a field when an error happened.
- How to should use Read-Only and how to use Disabled property of the field.
- How to distinguish the background color between the usage of ReadOnly and Disabled property of the field.