How to Toggle Readonly on Child Table Row

I want to make field amount of index 0 readonly. How do I do it?

frappe.ui.form.on("Purchase Invoice", "onload", function(frm){

frm.doc.installment[0].amount = 0.00;


I tried


but doesn’t work

also tried frm.doc.installment[0].toggle_enable(“amount”,false); but

frm.doc.installment[0].toggle_enable is not a function

tried Make child table field readonly
But it affects all rows, I want to change a specific row only

I tried cur_frm.get_field("installment").grid.grid_rows[0].columns.amount.df.read_only = 1;
index is 0, but still affects all rows

@johnskywalker any news on this?

Hi, was able to manage a workaround. User can still change the value, but on the trigger I save the old value and just set it again :smile:

1 Like

I see …

is that any update until now ? set specific child table row to be readonly ~


Take a look at Tax and Charges Child Table in Purchase Order, you’ll see that rate field will toggle according to selected charged_type field.

All code is here > apps/erpnext/erpnext/public/js/controllers/accounts.js

To simplify code is consist of 4 part

// File > doctype/<main_doctype_name>/<main_doctype_name.js
File > doctype/purchase_order/purchase_order.js

//frappe.ui.form.on("<Main DocType Name>", {
frappe.ui.form.on("Purchase Order", {

	// 1. This get triggered a lot, I don't know how to explain.
	setup: function(frm) {
		$(frm.wrapper).on("grid-row-render", function(e, grid_row) {
			//if(in_list(["<Child Table DocType Name>"], grid_row.doc.doctype)) {
			if(in_list(["Purchase Taxes and Charges"], grid_row.doc.doctype)) {
	// 2. This will be triggered when child table open form dialog
	//<child_table_field_names>_on_form_rendered: function(frm) {
	taxes_on_form_rendered: function(frm) {


//frappe.ui.form.on("<Child Table DocType Name>", {
frappe.ui.form.on("Purchase Taxes and Charges", {

	// 3. This will be triggered when charge_type is change
	//<field_names_in_child_table>: function(frm, cdt, cdn) {
	charge_type: function(frm, cdt, cdn) {
		var grid_row = frm.open_grid_row();
		if (!grid_row) {
			//grid_row = frm.get_field("<child_table_field_names>").grid.get_row(cdn)
			grid_row = frm.get_field("taxes").grid.get_row(cdn)


// 4. Toggle function
function toggle_test (grid_row) {

	var charge_type_is_actual = grid_row.doc.charge_type==="Actual"
	grid_row.toggle_editable("tax_amount", charge_type_is_actual);
	grid_row.toggle_reqd("tax_amount", charge_type_is_actual);
	grid_row.toggle_editable("rate", !charge_type_is_actual);
	grid_row.toggle_reqd("rate", !charge_type_is_actual);

Hope this help :grinning:

I tried to disable some fields when form load, I followed your code but it didn’t work.

But it works when i tried in browser console

grid_row = cur_frm.get_field("taxes").grid.get_row("b15286759b"); 
grid_row.toggle_editable("field_name", false);
1 Like

Hi try this:

frappe.db.get_value(“User”,frappe.session.user,“company”, function(v){
var data = frm.doc.taxes;
if ( !={
$("[data-idx=’"+e.idx+"’]").attr(‘readonly’, ‘true’);

You can Try This code, I hope can help you :grinning:

setup: function(frm){
	$(frm.wrapper).on('grid-row-render', function(e, grid_row) {
		if(in_list(['Sales Invoice Item'], grid_row.doc.doctype)) {
			if(grid_row) {
				if(grid_row.doc.item_group==="Misbah") {
					grid_row.toggle_editable("discount_multi_field_item", false);
					grid_row.toggle_editable("discount_multi_field_item", true);

I have tried your code and when

if (!grid_row) {
//grid_row = frm.get_field("<child_table_field_names>").grid.get_row(cdn)
grid_row = frm.get_field(“taxes”).grid.get_row(cdn)
above i am giving my child table’s field name it is showing can not read property of grid field so as u suggested in one of your post i gave form’s child table’s filed name and because of it when i am setting grid_row.toggle_editable(“score”,false) it is making all row’s score readonly.
please help me out.


Hi any update on my query/
Kindly help.

use this(grid_row.toggle_editable(“score”,false)) with some conditions.

means, make editable false if your condition is true

Ex. if(condition){