Is there any way to set the field as ReadOnly and still submit the value? As I know, if you set it as Disabled, the value won’t be submitted when saving.I tried add the following in my Add/Copy Page Startup Script and it also can’t work:
$("#btn-action").on("click", function () {
$("#x_MYFIELD1").prop("disabled", false);
$("#x_MYFIELD2").prop("disabled", false);
});
To further explain:I added the following in Add/Copy Page->Page_Load event. It does show correctly and the field was disabled:
You should use Row_Rendered server event instead of Page_Load to display the default values.Assume MYFIELD1 and MYFIELD2 are using Textbox controls, then put the following code in Row_Rendered server event.
function Row_Updating($rsold, &$rsnew)
{
$rsnew["work_type"] = $rsold["work_type"];
return true;
}
function Row_Inserting($rsold, &$rsnew)
{
$rsnew["work_type"] = "Work Order";
return true;
}
function Row_Rendered()
{
if ($this->work_status->CurrentValue == "Paid") {
$this->work_type->ReadOnly = true;
} else {
$this->work_type->ReadOnly = false;
}
}
work_type field is a radio buttons of “Work Order” and “Estimate”, when I open edit page it is readonly and one of two values “Work order” is selected but after hitting update button page refreshed and both radio buttons are unselected with error and if I see inpect code at this point
Now I do not know why disabled=“1” even I just used ReadOnly.work_type is required field and I checked it also after disabling “Required” but same error. Also I tried to do thing with edit page events but same result. I also used $this->work_type->Disabled instead of $this->work_type->ReadOnly same result.Kindly help me to sort it out. Also an alternative way like JS/JQuery with a code snippet and where to place that code will help me.I am registered user of v2023.
What is the field type of work_type? Is it an Integer/Numeric field? Or is it a String/Varchar field?In addition, did you use Lookup Table for that field, or did you use User Values for that field?
Okay. It seems the required information is pretty enough.However, since I have been using v2024, let me answer your question by using PHPMaker v2024.For Radio Button control, then you should not use ReadOnly property of the field. You may use Disabled property instead.So, the code in your Row_Rendered server event should be like this:
function Row_Rendered()
{
if (CurrentPageID() == "edit") {
if ($this->work_status->CurrentValue == "Paid") {
$this->work_type->Disabled = true;
} else {
$this->work_type->Disabled = false;
}
}
}
If you want to handle also for Add Page, for example, by default the value for Radio Button is “Work Order”, and you want to disable the control, then the code in Row_Rendered server event should be like this:
function Row_Rendered()
{
if (CurrentPageID() == "edit") {
if ($this->work_status->CurrentValue == "Paid") {
$this->work_type->Disabled = true;
} else {
$this->work_type->Disabled = false;
}
}
if (CurrentPageID() == "add") {
$this->work_type->CurrentValue = "Work Order";
$this->work_type->Disabled = true;
}
}
In addition, make sure also in Row_Inserting server event, your code like this:
// Row Inserting event
function Row_Inserting($rsold, &$rsnew)
{
// Enter your code here
// To cancel, set return value to false
$rsnew["work_type"] = "Work Order"; // don't forget this
return true;
}
Thanks for your help.Before coming to this forum I already tried Disabled and Readonly and many other possibilities but result is same.
All I know something is either missing or it is the PHPMaker which create such uncertainty. After a huge time wondering I come to the forum. This is because of no great documentation with good use cases is there. They never tell you in docs that radio buttons and textbox capacity about readonly and disabled etc.
If you think about any other solution, please guide me.
I have tried that code above first by using PHPMaker 2024, and it works properly. There is no error at all.Then, I’ve just tried it also by using PHPMaker 2023, a few minutes ago and it works properly, too.In addition to the code above, I also have the code in Row_Updating server event as follows:
// Row Updating event
function Row_Updating($rsold, &$rsnew)
{
// Enter your code here
// To cancel, set return value to false
if ($rsnew["work_status"] == "Paid")
$rsnew["work_type"] = "Work Order";
return true;
}
And one more thing, make sure also you have already updated the template to the latest version, just click on Tools → Update Template, and then re-generate ALL the script files, and try again.
I don’t know the condition when the Edit form is loaded for the very first time.
I meant, did you see the Type field has been selected for one of the provided options? If not, then it means perhaps you have existing record which has blank value for the Type field.
For such case, then you need to edit the value directly from database side, and not from the web application UI above.Another thing that you need to double check is, make sure the Type field is NOT setup as ReadOnly from Field setup.
did you see the Type field has been selected for one of the provided options?
Yes, I told in previous discussion that when we open edit page first time then “Work order” option is selected and after pressing save button both radio buttons are unselected. I do know why.
Another thing that you need to double check is, make sure the Type field is NOT setup as ReadOnly from Field setup.