ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

DocType field from readonly to editable


#1

Hello,
I want to do the following scenario: In a doctype I have a field (texteditor) where the users can write some comments. But I would like to have that field readonly at the first visit to the page and only when the user clicks on a button “edit comments” then the field will turn to editable. How can I achieve that?
Please give me detailed information since I am new in this environment.
Thank you
Makis


#2

Hi @emakis,

you can disable/enable field using cur_frm.toggle_enable(field_name, enable) method on client script.
pass enable = true or false depending on your requirement.

Thanks,
Makarand Bauskar


#3

@emakis welcome to the forum :smile:


#4

Hello i am trying to make vehicle_plate_number Read only field editable when transporter_type==“Sub-Contractor”. I have tried the following code below

  transporter_type:function(frm){
	if (frm.doc.transporter_type && frm.doc.transporter_type==="Sub-Contractor") {

		cur_frm.toggle_enable("vehicle_plate_number", true)
	}
	else{
		console.log("No sub contractor");
	}
},

Please help @makarand_b , thanks


#5

try this:

cur_frm.set_df_property(“vehicle_plate_number”,“read_only”,0);

reference:


#6

Thanks for getting back to me @magic-overflow , here is how i rewrote my code but still it’s not working.

 transporter_type:function(frm){
	if (frm.doc.transporter_type && frm.doc.transporter_type==="Sub-Contractor") {
		console.log("enable read only fields");

	    frm.set_df_property("vehicle_plate_number","read_only",0);
		frm.toggle_enable("vehicle_plate_number", true)

	}
	else{
		console.log("No sub contractor");
	    cur_frm.set_df_property("vehicle_plate_number","read_only",1);
	}
	frappe.after_ajax(function(){
		// frm.events.driver(frm);
		frm.refresh_field("vehicle_plate_number");
	})
},

#7

Delete

frm.toggle_enable(“vehicle_plate_number”, true)


#8

Thanks for getting back to me @magic-overflow , i managed to solve it by changing the field type to “Data” and selecting the read only box under Permissions section. So now i could change the fields from read only to editable with this line of code.

frm.set_df_property(“vehicle_plate_number”,“read_only”,0);