raknuth
Posts: 67
|
| Posted: 05/13/2011, 10:55 AM |
|
Hi. I have a form with the following 2 controls:
* textbox: name = theme_name; id = themestheme_name
* button: name = Button_Delete; id = themesButton_Delete
When the form is invoked to edit a record where the value of theme_name = "Default", I would like the following to happen:
1 - the textbox becomes read-only. If that cannot be done, would like to hide or disable it.
2 - the Delete button is hidden or disabled.
I have tried changing the textbox Visible property to Dynamic and then adding the Hide-Show Component action to its Before Show event, and have had no success. Here is the resultant code:
//Hide-Show Component @207-2D6B60B5
if (theme_name = "Default")
$Component->Visible = false;
//End Hide-Show Component
Once I make the textbox work, I should be able to apply the same technique to the Delete button.
What am I doing wrong? In advance, I thank you.
|
 |
 |
datadoit
|
| Posted: 05/13/2011, 10:59 AM |
|
You want to use $Component->GetValue() == "Default" for the condition.
|
|
|
 |
raknuth
Posts: 67
|
| Posted: 05/13/2011, 6:02 PM |
|
That did not make it work. Thanks for trying, though.
|
 |
 |
andy
Posts: 183
|
| Posted: 05/14/2011, 1:22 AM |
|
Try this in the Form's BeforeShow server side event:
Global $myform;
$def=$myform->theme_name->GetValue();
if ($def == "Default") {
$myform->theme_name->Visible = false;
$myform->Button_Delete->Visible = false;
}
_________________
Andy
RAD tools for rich UI controls:
http://www.koolphptools.com |
 |
 |
Waspman
Posts: 948
|
| Posted: 05/14/2011, 1:51 AM |
|
Yeah, I'd do it as Andy said. Doing it in the components beforeshow wouldn't work, it's too late.
_________________
http://www.waspmedia.co.uk |
 |
 |
raknuth
Posts: 67
|
| Posted: 05/14/2011, 7:05 PM |
|
Thank you. That works perfectly.
|
 |
 |
raknuth
Posts: 67
|
| Posted: 05/16/2011, 5:09 PM |
|
New development. Although I am able to hide the textbox, the Update method wants a value for the theme_name field. Evidently, this field/value pair is omitted when the field is not visible. How do I keep the control invisible and still force the Update method to work with theme_name = Default?
|
 |
 |
Waspman
Posts: 948
|
| Posted: 05/17/2011, 1:34 AM |
|
So it's a required field?
or set the fields default value on insert/update
_________________
http://www.waspmedia.co.uk |
 |
 |
raknuth
Posts: 67
|
| Posted: 05/17/2011, 8:24 AM |
|
It is a required field.
The value of the field must be unique. In the record 'shipped' with the table, this value = 'Default'. I don't want that value changed, nor do I want the user to delete this record. When the user creates a new record, he assigns a unique value to this field. So there is no logic to setting a default value.
|
 |
 |
Waspman
Posts: 948
|
| Posted: 05/17/2011, 9:58 AM |
|
If it's hidden does it matter?
Whatever dictates the visibility of the textfield can also dictate the value of the field
_________________
http://www.waspmedia.co.uk |
 |
 |
raknuth
Posts: 67
|
| Posted: 05/17/2011, 10:13 AM |
|
Although it continues to baffle me, it evidently does matter. If the theme_name field is visible, I can change the value in another field and successfully save the record. If the theme_name field is invisible, I cannot save the changes. The error at the top of the form reads 'The value in field Theme Name is required'. And the field has been rendered visible again, but with no value within (it is empty).
Something in the code apparently demands that a field be visible if the value is to be included in the Update process. Where and how do I create theme_name = "Default" prior to the Update events?
|
 |
 |
Waspman
Posts: 948
|
| Posted: 05/17/2011, 11:35 AM |
|
Custom code in before update or insert and add a condition based on what was used to set the visibility in the first place
_________________
http://www.waspmedia.co.uk |
 |
 |
raknuth
Posts: 67
|
| Posted: 05/20/2011, 12:25 PM |
|
Finally, a working solution. Thanks for staying with me on this.
Here is what I did:
1 - in the theme_name control, set Required to 'false' and Visible to 'dynamic'.
2 - created a Panel named 'pnlThemeName'; set Visible to 'false'.
3 - within the Panel, created a Label named 'lblThemeName'; set Control Source to 'theme_name'.
4 - in the form code, added a BeforeShow event as follows:
------
Global $themes;
$def=$themes->theme_name->GetValue();
if ($def == "Default") {
$themes->theme_name->Visible = false;
$themes->Button_Delete->Visible = false;
$themes->pnlThemeName->Visible = true;
CCSetSession(IsDefaultTheme,1);
} else {
CCSetSession(IsDefaultTheme,0);
}
/*
(if theme_name = "Default", user sees only the label. If not "Default", user sees the editable textbox. The new session variable will help me track this event, as setting Visible to 'false' seems to empty the former value of theme_name. Fortunately, the Update process does not update theme_name with this empty value.)*/
-----
5 - created Custom Code in the theme_name Server OnValidate event, as follows:
-----
global $themes;
if (CCGetSession(IsDefaultTheme) == 0 && $themes->theme_name->GetValue() == "") {
$themes->Errors->addError("Theme Name must not be empty");
}
-----
Wow, that was painful! But I am learning. I thank you all for your patience.
|
 |
 |