动态更改按钮颜色 [英] Dynamically Change Button Color

查看:103
本文介绍了动态更改按钮颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将PXAction添加到自定义Graph扩展类。这将在屏幕顶部放置一个按钮。我想在代码中动态更改按钮的颜色。我怎样才能做到这一点?



我正在使用版本19.100.0122



TIA!

解决方案

请注意,Acumatica ISV认证计划不允许这些类型的更改。



您可以使用JavaScript更改CSS样式。在自定义项目编辑器允许的任何位置添加JavaScript元素:



填写脚本属性,将其设置为启动脚本,并将以下JavaScript放入script属性中(您需要将 Test更改为Action的显示名称):

  function setActionButtonColor(){
var x = document.getElementsByClassName( toolsBtn);
var i;

for(i = 0; i< x.length; i ++){
//将测试替换为操作按钮
的显示名称,如果(x [ i] .getAttribute( data-cmd)=== Test)
x [i] .style.backgroundColor = red;
}
}



打开页面时,将执行JavaScript方法并更改操作按钮的背景颜色:



我对此图扩展进行了测试:

 公共类SOOrderEntry_Extension:PXGraphExtension< SOOrderEntry> 
{
public PXAction< SOOrder>测试;

[PXUIField(DisplayName = Test)]
公共虚拟IEnumerable Test(PXAdapter适配器)
{
return adapter.Get();
}
}


I have added a PXAction to a custom Graph extension class. This places a "button" at the top of the screen. I want to dynamically change the color of the button in code. How can I do that? Is it possible?

I am using version 19.100.0122

TIA!

解决方案

Note that those types of changes are not allowed by Acumatica ISV Certification program.

You can use JavaScript to change the CSS styles. Add a JavaScript element anywhere that the customization project editor will allow you:

Fill in script properties, set it as a startup script and put the following JavaScript in the script property (you'll need to change "Test" to the display name of your Action):

function setActionButtonColor(){  
   var x = document.getElementsByClassName("toolsBtn");
   var i;

   for (i = 0; i < x.length; i++) {
     // Replace "Test" by the display name of your action button
     if (x[i].getAttribute("data-cmd") === "Test")
        x[i].style.backgroundColor = "red";
   } 
} 

In DataSource ClientEvents->CommandPerformed property you put the name of the JavaScript method to call (setActionButtonColor):

When opening the page JavaScript method is executed and changes the background color of the Action button:

I tested with this graph extension:

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
 public PXAction<SOOrder> test;

 [PXUIField(DisplayName = "Test")]
 public virtual IEnumerable Test(PXAdapter adapter)
 {
   return adapter.Get();
 }
}

这篇关于动态更改按钮颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆