[英]Enabling/Disabling button with Javascript
Problem : I have an apex:commandButton on a VisualForce page, and a js file with some logic in it. 问题:我在VisualForce页面上有一个apex:commandButton,并且其中包含一些逻辑的js文件。 Currently, this logic affects whether the button is visible or invisible on the page, using css. 当前,此逻辑使用CSS影响按钮在页面上是可见还是不可见。 I need to change this so it makes the button enabled or disabled. 我需要更改此设置,以使其启用或禁用按钮。 However, whenever I try to disable the button in the js file, the onscreen button doesn't get affected. 但是,每当我尝试禁用js文件中的按钮时,屏幕上的按钮都不会受到影响。 I am not experienced with front-end dev so may be missing or misunderstanding something obvious. 我对前端开发人员没有经验,因此可能会丢失或误解一些明显的东西。
Button on .page file : .page文件上的按钮:
<apex:commandButton id="commitButton"
action="{!commitSelectedLines}"
value="{!$Label.commitSelectedLines}"/>
.js file (heavily edited down to the seemingly relevant bits) : .js文件(已大幅度地修改为看似相关的位):
FFDCBalancer = (function(){
/**
* Singleton Balancer object to maintain balances on the page.
*/
var balancer = {
/** JQuery button component for the commit button. */
cmdCommit: undefined,
/** Set the enabled-ness of the commit button. */
setCommitEnabled : function(value) {
//I PRESUMABLY NEED TO CHANGE THIS BIT TO USE 'DISABLED'.
this.cmdCommit.css({
'display': value ? 'block' : 'none'
});
//I HAVE TRIED VARIOUS BITS OF CODE, SUCH AS THIS
//this.cmdCommit.disabled = value;
},
/**
* Respond to refresh by connecting event handlers and calculating the balances.
*/
onRefresh : function () {
var me = this;
me.cmdCommit = $FFDC('#commitButton');
}
};
$FFDC(document).on('FFDCRefresh', function(){ balancer.onRefresh(); });
return balancer;
}());
For this, you can do one of two things: 为此,您可以执行以下两项操作之一:
Use the {!$Component...commitButton} to get the client-side ID, though it can really mess JQuery up, since it adds a colon between the IDs, so you'll have to use it in combination with document.getElementById(...) - For example: 使用{!$ Component ... commitButton}来获取客户端ID,尽管它确实会使JQuery混乱,因为它在ID之间添加了一个冒号,因此您必须将其与document.getElementById结合使用(...) - 例如:
jQuery(document.getElementById('{!$Component.Form.commitButton}')).attr('disabled','disabled');
Put a "styleClass" on the button, and change it using that: 在按钮上放置一个“ styleClass”,并使用该样式进行更改:
<apex:commandButton id="commitButton" action="{!commitSelectedLines}" value="{!$Label.commitSelectedLines}" styleClass="commitButtonClass" />
Then use jQuery to set the attribute: 然后使用jQuery设置属性:
jQuery(".commitButtonClass").attr('disabled','disabled');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.