Dynamically Change Button Color

2019-08-19 00:20发布

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!

标签: acumatica
1条回答
三岁会撩人
2楼-- · 2019-08-19 00:45

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: enter image description here

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";
   } 
} 

enter image description here

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

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

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();
 }
}
查看更多
登录 后发表回答