Following my previous post, I made another form with more complex functionality.
In this case, I have two dummy cfinputs instead of only one. Adding a second input helps getting around the limitations I had mentioned in my last post.
Following my previous post, I made another form with more complex functionality.
In this case, I have two dummy cfinputs instead of only one. Adding a second input helps getting around the limitations I had mentioned in my last post.
One of the cfinputs is linked to the other so that when the input "userType" sets its value, the change is caught by input "trigger" that fires the onLoad event. We are now able to access some values inside the onLoad, such as the value of "userType" because of the order of the events that are executed.
This also solves the limitation of needing to place the triggering input at the end, we can put it anywhere.
In this example, the behavior of the onload event depends on a variable (userLevel) set at the top for simplicity. userLevel equals to 0 means that the user is an administrator, in which case, we let the user access the form. The onLoad function checks what is the level of the user and disables the form if he/she is not an administrator.
You can download the source and play with the variable "userLevel" to see the changes.
Code:
if(userType.text != 0){
alert("Sorry but only the administrator can change this setting" ,'Warning Message',mx.controls.Alert.OK);
newUser.enabled = false;
}
{(userType.text != '') ? userType.dispatchEvent({type:'change'}) : ''}"
View the example as user and as admin.
Download the source
Update: This hack is no longer needed after ColdFusion updater 7.01