Disable modifying a field depending on user and its value

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
Roland
User
Posts: 24

Disable modifying a field depending on user and its value

Post by Roland »

Using PHPMaker v2017.0.7

In Table-Specific | Edit Page | Page_Render, I wrote:

function Page_Render() {
//echo "Page Render";
if (CurrentUserLevel() != -1) {
if ($this->editor->CurrentValue != 0) {
$this->editor->ReadOnly = TRUE;
}
}
}

editor is a tinyint(1) field which can be NULL or 1,2,3, ... and works with a combobox.
With my code, the field is grey but it is possible to select another value and save it.

Any help much appreciated. Thank you.


mobhar
User
Posts: 11660

Post by mobhar »

Change:
$this->editor->ReadOnly = TRUE;

to:
$this->editor->Disabled = TRUE;

In addition, since the control is disabled, then you need to handle the default value for that field from "Row_Updating" server event in order to avoid the empty/null value, for example:
$rsnew["editor"] = "Your default value goes here"; // <-- just adjust it to your desired value


Roland
User
Posts: 24

Post by Roland »

Thank you!

Change:
$this->editor->ReadOnly = TRUE;
to:
$this->editor->Disabled = TRUE;

It works fine.
Question: Is this code correct in Table-Specific | Edit Page | Page_Render or should it be better to move it to Table-Specific | Common | Row_Rendered?

In addition, since the control is disabled, then you need to handle the default value for that field from "Row_Updating" server event in order to avoid the empty/null value,
Yes indeed.

for example:
$rsnew["editor"] = "Your default value goes here"; // <-- just adjust it to your desired value

I tried some solutions without success...
Question: Do you mean that I have to save something like

$rsold["editor"] = myvalue (in Page_Render)
then add
$rsnew["editor"] = myvalue (in Row_updating)
?

I have read "Server Events and Client Scripts" from top to bottom but I should appreciate any good piece of code ;-)
Thank you!


mobhar
User
Posts: 11660

Post by mobhar »

Roland wrote:
Question: Is this code correct in Table-Specific | Edit Page | Page_Render or should
it be better to move it to Table-Specific | Common | Row_Rendered?

It actually depends on your needs. If you want to do that only for Edit Page, then "Page_Render" that belongs to "Edit Page" only should be better. If you want to put it in "Row_Rendered" and you don't want that code to be implemented in another page, then you should add your if condition to check whether the current page is Edit Page or not. Please note that "Row_Rendered" will be implemented for not only Edit Page also, but for other pages, too such as List Page, View Page, Add Page, and so forth.

Roland wrote:
$rsold["editor"] = myvalue (in Page_Render)

There is no $rsold object in "Page_Render" server event, thus that code is useless and should rise an error.


Roland
User
Posts: 24

Post by Roland »

Thank you!

Mobhar wrote:
There is no $rsold object in "Page_Render" server event, thus that code is useless and should rise an error.

Ok

In addition, since the control is disabled, then you need to handle the default value for that field from "Row_Updating" server event in order to avoid the empty/null value, >for example:
$rsnew["editor"] = "Your default value goes here"; // <-- just adjust it to your desired value

Having read a lot of topics, I do not understand what you mean with "default value" (or desired value). Is it the value of the "editor" field when this field has been "disabled" in Edit Page?

Thank you.


mobhar
User
Posts: 11660

Post by mobhar »

Roland wrote:
Is it the value of the "editor" field when this field has been "disabled" in Edit Page?

Yes, it is.


Post Reply