Page 1 of 1

Changing the color of a button if it is disabled

Posted: 06 May 2021, 12:26
by Krisztyan
Hi Guys,

I am using Rain theme. I would like to change the color of my button if it disabled.
I would like to change the color of the button to light grey if it is disabled. If it is not disabled it is red.

Can please someone tell me how to do that?

<p:commandButton id="cancelButton"
value="#{msg['prod.cancel']}"
icon="fas fa-undo" styleClass="danger-button p-mr-2"
style="width:auto;" ajax="true" update="update"
actionListener="#{cancelProd}"
disabled="#{!prod.isCancelable()}">
<p:confirm
...etc>
</p:commandButton>

Many thanks and best regards,
Krisztyan

Primefaces version: 8.0.4
Rain theme: 1.0.0

Re: Changing the color of a button if it is disabled

Posted: 07 May 2021, 08:14
by mert.sincan
Hi,

Please try;

Code: Select all

<p:commandButton styleClass="#{!prod.isCancelable() ? 'custom-light-grey' : 'danger-button'} p-mr-2" disabled="#{!prod.isCancelable()}">
Best Regards,

Re: Changing the color of a button if it is disabled

Posted: 07 May 2021, 10:27
by Krisztyan
Hi Mert Sincan,

thank you for your help. Now the color of the button is light grey as expected.

Unfortunately now I lost the margin to the right. p-mr-2 not recognized.
I have two buttons next to each other in the same line horizontally and there is no margin between them anymore.

The styleclass of the two buttons are the same.

Like:

Code: Select all


First:
styleClass="#{!prod.isCancelable() ? 'custom-light-grey' : 'danger-button'} p-mr-2}" disabled="#{!prod.isCancelable()}">	
Second:
styleClass="#{!prod.isCancelable() ? 'custom-light-grey' : 'danger-button'} p-mr-2}" disabled="#{!prod.isCancelable()}">	

																
										
Could you please help with that?

Many thanks and best regards,
Krisztyan

Re: Changing the color of a button if it is disabled

Posted: 07 May 2021, 11:37
by Krisztyan
Ahhh OK got it. I had a } in the expression.

Super thanks for your help!

Re: Changing the color of a button if it is disabled

Posted: 07 May 2021, 16:09
by siris
Thanks @mert.sincan