Total field custom script

Basically not, on my system it works fine without.
But yes, try it… you can extand =“red” with =“red !important”

If it dont work too, send me please your hole script and i will crosscheck it

!important property is also not working.

below is my whole script

frappe.ui.form.on(“Partnership”, “partnership_percent”, function(frm, cdt, cdn) {

var material_details = frm.doc.partnership_information;
var total = 0
for(var i in material_details) {
total = total + material_details[i].partnership_percent
}

frm.set_value("total_percentages",total)
if(frm.doc.total_percentages >100)
{
	frappe.msgprint("Total Percentage Cannot be Greater Than 100%");

document.querySelectorAll(“[data-fieldname=‘total_percentages’]”)[1].style.color=“red !important”;

}

});

not working with background-color / color.

Ok, basically the script looks good. Exepct some “;” are missing, check this first please.

The field is not(!) a field of an childtable, correct?

frappe.ui.form.on(“Partnership”, “partnership_percent”, function(frm, cdt, cdn) {

var material_details = frm.doc.partnership_information;
var total = 0;
for(var i in material_details) {
total = total + material_details[i].partnership_percent;
}

frm.set_value("total_percentages",total);
if(frm.doc.total_percentages >100)
{
	frappe.msgprint("Total Percentage Cannot be Greater Than 100%");

document.querySelectorAll(“[data-fieldname=‘total_percentages’]”)[1].style.color=“red”;

}

});

i’ve put the missing “;” but not working.

and the field “total_percentages” is not a field of childtable.

Sorry @joelios i am taking your too much time.
but i am stuck in this. :frowning:

Hmm im stock too at the moment, this is very strange…because on my site it works nice…

You could try to call the following part of the script in an other trigget. I would take the “refresh”-trigger…

if(frm.doc.total_percentages >100)
{
frappe.msgprint(“Total Percentage Cannot be Greater Than 100%”);

document.querySelectorAll(“[data-fieldname=‘total_percentages’]”)[1].style.color=“red";
}

can you please write a refresh script for me.
Sorry for my noobiness in scripts :confused:

I will look at it again when im back home…

Dont worry, we’ll find a soloution :wink:

Thank you so much friend.
i am waiting.

So, I have replayed your scenario and the following script works fine with my testsystem as you can see on the prinstscreens:

field total <= 100:
grafik

field total > 100 (after save!):

I used this customscript:

frappe.ui.form.on("Partnership", {
	refresh: function(frm) {
		var total = 0;
		
		partnership_information.forEach(function(material_details) {
			total = total + material_details.partnership_percent;
		});

		frm.set_value("total_percentages", total);
		
		if(total > 100) {
			frappe.msgprint("Total Percentage Cannot be Greater Than 100%");
			document.querySelectorAll("[data-fieldname='total']")[1].style.backgroundColor="red";
		} else {
			document.querySelectorAll("[data-fieldname='total']")[1].style.backgroundColor="white";
		}
	}
});

If this script does not work for you either, we have to look at the html code of your doctype…i hope not :wink:

in addition or alternatif:
can use
$(‘input[data-fieldname=“total”]’).css(“color”,“red”)

beside,
document.querySelectorAll(“[data-fieldname=‘total’]”)[1].style.backgroundColor=“red”;

notes:
but, if you checked read only in “total” field, both scripts above can not run.

@joelios your script isn’t working in my site after save.
even not calculating total percentage and not showing msgprint’s msg.

Thank you so much @komsel2228 it is working after i unchecked read only.

& Specially thanks to @joelios.
Thank you boy for your all help & your time.
I’ll never forget what you did for me.
Thanks again.

1 Like