Is there a way to specify the color of a custom button specified in a DocType, similar to the red “Delete” button?
![]()
Is there a way to specify the color of a custom button specified in a DocType, similar to the red “Delete” button?
![]()
Uses the bootstrap classes. Jquery find the button and add/remove/change the class.
document.querySelectorAll("[data-fieldname='button_name']")[1].style.backgroundColor ="red";
Hey @shahid, see if you can add this trick to the client scripting page in the wiki.
Actually… it looks like wiki needs a lot of attention…
@tmatteson Yes i’ll like to add, but how?
Thanks. I will try that code later today and confirm.
@shahid Thanks for taking the time to add that to the wiki. It really helps us new developers get up to speed faster and become better contributors to the project.
I would suggest “Client side script to change CSS properties of Doctypes.”
Before you get that far though, I want to discuss a couple points of style. And maybe get an opinion from @netchampfaris Faris.
querySelector and $().find) leads to problems.@shahid Have you confirmed this script works? I have been unsuccessful getting a form button to change color.
In the doctype company, there’s a red button that’s used to delete transaction for a company. This is the method I use.
use this it works 100%
onload_post_render: function(frm) {
frm.get_field(“button_name”).$input.addClass(“btn-primary”);
}
Hi,
I am using this code snippet for changing background color of data field of a doctype but it is not working .
Please help me out.
Regards ,
Vishakha
Hello @Taniyavish
Please use this below script. It works for me.
Custom Script:
frappe.ui.form.on(“Test”, {
refresh: function(frm) {
set_css(frm);
}
});
var set_css = function (frm) {
let el = document.querySelectorAll(“[data-fieldname=‘email’]”)[1].style.backgroundColor =“lightskyblue”;
let fl = document.querySelectorAll(“[data-fieldname=‘phone’]”)[1].style.backgroundColor =“mediumaquamarine”;
}
Result:
Hope this helps.
Regards,
Sujay
Thanks @Sujay,it also worked for me.![]()
HI all,
id like to change the color of the field based on the value of the field,
for example if the field value is saturday it should chnage to red
pls do help.
thanks.