This topic is locked

How to disable/enable controls on Edit/Add pages

10/13/2007 7:36:44 AM
PHPRunner Tips and Tricks
Sergey Kornilov admin

This code snippet makes state dropdown disabled if other than US country is selected
PHPRunner5.0/5.1
Add the following code to the end of Add/Edit page in Visual Editor in HTML mode.

<script>

document.forms.editform.value_country.onchange=function()

{

if(this.options[this.selectedIndex].value=='US')

document.forms.editform.value_state.disabled=false;

else

{

document.forms.editform.value_state.disabled=true;

document.forms.editform.value_state.value='';

}

}

</script>


PHPRunner 5.2:
Add the following code snippet to OnPageLoadAdd/OnPageLoadEdit javascript event:

<script>

var tName = 'TableName';

var ctrlCountry = Runner.controls.ControlManager.getAt(pageid, 'Country');

var ctrlState = Runner.controls.ControlManager.getAt(pageid, 'State');
ctrlCountry.on('change', function(e){

if (this.getValue() == 'US'){

ctrlState.setEnabled();

ctrlState.addValidation("IsRequired");

}else{

ctrlState.setDisabled();

ctrlState.setValue("");

ctrlState.removeValidation("IsRequired");

}

});

</script>


PHPRunner 5.3:
Add the following code snippet to OnPageLoadAdd/OnPageLoadEdit javascript event:

<script>

var ctrlCountry = Runner.getControl(pageid, 'Country');

var ctrlState = Runner.getControl(pageid, 'State');
ctrlCountry.on('change', function(e){

if (this.getValue() == 'US'){

ctrlState.setEnabled();

ctrlState.addValidation("IsRequired");

}else{

ctrlState.setDisabled();

ctrlState.setValue("");

ctrlState.removeValidation("IsRequired");

}

});

</script>
M
mrpeeble 10/24/2007

Add the following code to the end of Add/Edit page in Visual Editor in HTML mode.

This code snippet makes state dropdown disabled if other than US country is selected.

&lt;script>

document.forms.editform.value_country.onchange=function()

{

if(this.options[this.selectedIndex].value=='US')

document.forms.editform.value_state.disabled=false;

else

{

document.forms.editform.value_state.disabled=true;

document.forms.editform.value_state.value='';

}

}

</script>


Hi,

I added the code to the end of the _edit.htm with my own field names:
<script>

document.forms.editform.value_IRPaymentAction.onchange=function()

{

if(this.options[this.selectedIndex].value=='Hold Cheque')

document.forms.editform.value_IRCaseAction.disabled=false;

else

{

document.forms.editform.value_IRCaseAction.disabled=true;

document.forms.editform.value_IRCaseAction.value='';

}

}

</script>
I get the following error:
Error type 256

Error description Smarty error: [in pr_main_edit.htm line 81]: syntax error: unrecognized tag: if(this.options[this.selectedIndex].value=='Hold Cheque') document.forms.editform.value_IRCaseAction.disabled=false; else { document.forms.editform.value_IRCaseAction.disabled=true; document.forms.editform.value_IRCaseAction.value=''; (Smarty_Compiler.class5.php, line 436)

URL 137.15.236.240/officel/5percent2008/pr_main_edit.php?editid1=3

Error file D:\WebDev\OfficeL\5percent2008\libs\Smarty.class5.php

Error line 1095

SQL query select `ID`, `MemberID`, `Surname`, `GivenName`, `FileLocated`, `IRPaymentAction`, `IRCaseAction`, `IRSignOff`, `IRDate`, `48HRPaymentAction`, `48HRCaseAction`, `48HRSignOff`, `48HRDate`, `CutOffCaseAction`, `CutOffSignOff`, `CutOffDate`, `MyTimeStamp`, `PaymentNumber`, `Comments`, `IREdit` From `pr_main` where `pr_main`.`ID`=3
Any help would be appreciated
thank you,
tom

M
Max68 10/26/2007

I don't kwon if this can help you, but i've done this
put in the header of the edit page:

&lt;script language="JavaScript" type="text/javascript" src="numberFormat154.js"></script>

(i don't know if it is necessary, i've not tried without this)
at the end (before the tag of body end) put

{literal}

&lt;script language="JavaScript" type="text/javascript">

document.forms.editform.value_giornate.onchange=function()

{

if(this.options[this.selectedIndex].value=='Definite')

document.forms.editform.value_n_gg.disabled=false;

else

{

document.forms.editform.value_n_gg.disabled=true;

document.forms.editform.value_n_gg.value='';

}

}

</script>

{/literal}

(without "literal" don't works)
Max

M
Max68 10/26/2007

I am sorry, this part is to delete.
<script language="JavaScript" type="text/javascript" src="numberFormat154.js"></script>

(it is relative to another function in the page)
Max

M
mrpeeble 10/29/2007

I am sorry, this part is to delete.

&lt;script language="JavaScript" type="text/javascript" src="numberFormat154.js"></script>

(it is relative to another function in the page)
Max


Max, thanks for your assistnace. You are correct, the code needed the literal tags to function. Now it works pretty good when the onchange event fires, but I need the field to be locked when the page loads, not just when changing to one of the values where a lock is specified. If anyone knows how to do this, please let us know.

M
Max68 10/31/2007

Max, thanks for your assistnace. You are correct, the code needed the literal tags to function. Now it works pretty good when the onchange event fires, but I need the field to be locked when the page loads, not just when changing to one of the values where a lock is specified. If anyone knows how to do this, please let us know.


I hope that this can help you:
In the event EditOnLoad (of Editpage) put code like this:
global $data;

if($data["giornate"]=="Definite")

echo "<script language=javascript>document.editform.value_n_gg.disabled=false;</script>";

else

{

echo "<script language=javascript>document.editform.value_n_gg.disabled=true;</script>";
}
The "EditOnLoad" event must be on the bottom of the page (can do this on the Visual editor).

V
vcane 11/27/2007

I put this in Editpage and dont work to my, please a need you help is very usufull to my enable and disable control based in other control values in add/edit pages.
Thanks
Virgilio , sorry my english is bad
In the event EditOnLoad (of Editpage) put code like this:
global $data;

if($data["giornate"]=="Definite")

echo "&lt;script language=javascript>document.editform.value_n_gg.disabled=false;</script>";

else

{

echo "&lt;script language=javascript>document.editform.value_n_gg.disabled=true;</script>";
}
The "EditOnLoad" event must be on the bottom of the page (can do this on the Visual editor).

[/quote]

M
Max68 12/7/2007

in my case works correctly, naturally, i think you have done, you must change the names of variables to match to your case.

I've put the example that must be modified.
in red there are the variables that you must change
global $data;

if($data["")

echo "&lt;script language=javascript>document.editform.value_[color=#FF0000]n_gg.disabled=false;</script>";

else

{

echo "&lt;script language=javascript>document.editform.value_n_gg.disabled=true;</script>";
}

I
indigo 4/15/2008

What do I do if I want to disable multiple fields? Apparently its not working for the same.

{literal}

<script language="JavaScript" type="text/javascript">

document.forms.editform.value_Status.onchange=function()

{

if(this.options[this.selectedIndex].value=='Completed')

document.forms.editform.value_ProjectName.disabled=true;

document.forms.editform.value_StartDate.disabled=true;

document.forms.editform.value_StartTime.disabled=true;

else

{

document.forms.editform.value_ProjectName.disabled=false;

document.forms.editform.value_StartDate.disabled=false;

document.forms.editform.value_StartTime.disabled=false;

}

}

</script>

{/literal}

M
mathias@mylo.be 2/23/2010

Hi,
I've tried this in one of my recent 5.2 projects, but it doesn't seem to work anymore. Has there been a change in the necessary code?
Regards,

Mathias

M
mmponline 3/17/2010

Also need to know what way is needed to hide / show a field based on the value chosen in first field. - For V5.2
Eg. fields

CreditCard Yes/No

Don't show CreditCardNo, Company, etc.

When yes, display the CreditCardNo. Company, etc.
Help appreciated!

S
SANDY 8/5/2010



This code snippet makes state dropdown disabled if other than US country is selected
PHPRunner5.0/5.1
Add the following code to the end of Add/Edit page in Visual Editor in HTML mode.

<script>

document.forms.editform.value_country.onchange=function()

{

if(this.options[this.selectedIndex].value=='US')

document.forms.editform.value_state.disabled=false;

else

{

document.forms.editform.value_state.disabled=true;

document.forms.editform.value_state.value='';

}

}

</script>


PHPRunner 5.2:
Add the following code snippet to OnPageLoadAdd/OnPageLoadEdit javascript event:

<script>

var tName = 'TableName';

var ctrlCountry = Runner.controls.ControlManager.getAt(pageid, 'Country');

var ctrlState = Runner.controls.ControlManager.getAt(pageid, 'State');
ctrlCountry.on('change', function(e){

if (this.getValue() == 'US'){

ctrlState.setEnabled();

ctrlState.addValidation("IsRequired");

}else{

ctrlState.setDisabled();

ctrlState.setValue("");

ctrlState.removeValidation("IsRequired");

}

});

</script>



THIS CODE IS NOT WORKING

M
mmponline 8/5/2010



THIS CODE IS NOT WORKING


Found the same. I can't get it to work as well. I see that this will be part of the new 5.3 version, but that is still about 3 months away before we'll have a final version.
Any one with help on getting this to work?

I
inko_nick 8/15/2010

For v5.2

Change "Runner.controls.ControlManager.getAt" to "Runner.getControl"
EX: Runner.controls.ControlManager.getAt(pageid, 'Country') -> Runner.getControl(pageid, 'Country');