Disable a button or make it readonly
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-11-2010 11:06 AM
Hi , I have added a new button on the form and its corresponding action. works good. I need to make it appear active conditionally on the form but not hide it. Just to make it disabled when the condition does not meet and not completely hide. Instead, show it but should not be active.
something like if(condition) (button.disabled=true) else (button.disabled=false)
I know this can be achieved through script, but how to grab the button id/name.
Thanks,
Shiva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2010 11:13 AM
I had created two scripts
function onLoad() {
var rpBtn = g_form.getControl('request.approval');
rpBtn.disabled = true;
//alert("test");
}
and another script for onchange event of a text field
var reqBtn = g_form.getControl("request.approval");
// reqBtn.visible = "true";
reqBtn.visible = true;
and "request.approval" is the action name associated with the button. i also tried with "request_approval" since "Request Approval" is the button name.
There are other UIpolicies (ex.mandatory fields, readonly, defualted values) active on the form.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2010 11:42 AM
For your onLoad client script try using this:
function onLoad() {
var rpBtn = document.getElementById("request_approval");
rpBtn.disabled = true;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2010 11:55 AM
Yes, i had already tried that. Rechecked now too.
Now another strange thing happens when i make this above said script, the UI policy for mandatory fields on this form fail. It works when i deactivate my script.
And fyi, i have a condition and below script in the UI action associated with the button.
action.setRedirectURL(current);
current.approval='requested';
current.state= 2;
current.update();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2010 12:17 PM
Something is creating a conflict or an error for sure. Do you use Firefox with the Firebug add-on by chance? You could use Firebug to track the source of the error and even go through the html of the page to make sure you have the correct id for the button that you wish to disable. I have this script running on a few buttons in my instance and it works for my forms.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-12-2010 12:31 PM
If you are using this with the OOB Request Approval button on the change form the button id is actually request.approval so the script would be.
function onLoad() {
var rpBtn = document.getElementById("request.approval");
rpBtn.disabled = true;
}