Read-Only field showing data after Saving the doc

I am composing a message using multiple fields and appending that data to a small text field. I don’t want anyone to edit that main field where message is being created so I made that field read-only. But what is happening is It is not showing value until I save the doc. But what I want is at the time each field’s value is pushed (appended) to main message body field, it should be visible to me but I cant edit or modify it. Read-Only didn’t worked out here. Any way to achieve so using any alternate approach let say custom script

This is what I tried

 $(document).ready(function(){
        $("[data-fieldname='message']").prop('readonly', true);
})

Also tried

.prop('disabled'true) & .prop('disabled','disabled')

But none of that worked.

Also when i inserted readonly=true in that textarea, it worked as perfect as I want. So i just need to add that property using custom script.

By doing through console of browser, this is what it is by default:

<textarea type="text" autocomplete="off" class="input-with-feedback form-control bold" data-fieldtype="Small Text" data-fieldname="message" placeholder="" data-doctype="Draft"  style="height: 150px;"></textarea>

This is what I want to achieve:

<textarea type="text" autocomplete="off" class="input-with-feedback form-control bold" data-fieldtype="Small Text" data-fieldname="message" placeholder="" data-doctype="Draft" readonly="true" style="height: 150px;"></textarea>

Check this, you’ll get an ideas.

Thanks for replying. I tried it is now overriding the readonly property of that field and it is now editable

if (cur_frm.doc.__islocal){
   cur_frm.set_df_property("message", "read_only", cur_frm.doc.action !="");
}

Doesn’t helped in my case. Any other approach

Readonly filed only shows when has value.

If you want to show it, so just give set value.

cur_frm.set_value(“your_readonly_filed”, “any”)

or

change it to editable first, then change it to read_only after appending value.

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

then after appending value

cur_frm.set_df_property(“your_readonly_filed”, “read_only”, 1);

set_value is exactly what I am using, in ERPNext v10 it is working perfect but this problem is coming in v11 (staging). Although in console it is showing value set to that field (in v11) but is not shown on form untill I save it

It works on v11 staging. employee_name is read-only field. I tested it on demo.erpnext.com

Edit:
employee_name is Full Name in form.

I am pushing value from field A to field B. Field A is where I am giving input and Field B is the readonly field. On v10 when I enter value to A and on tab or clicking,that value gets pushed in Field B and that field is shown But on v11 on doing same that field is not visible untill I save it :roll_eyes:

When I am not making that field as readonly, then I can clearly see value pushed to field B on insertion in Field A.

Here’s my local VM running v11 staging.

custom script

when input first name, then full name shows up:

Thats exactly what I’m doing. One more thing , make that Full Name field Small Text and then try

Changed to small text

It still works:

Small Text:

Ok. Don’t know why it isn’t working in v11 in my case although same customization on v10 is working perfectly

I still didn’t get it. While on Small-Text and making that field Read-Only, it wasn’t showing the value but when I made its Read-Only field type , it is working.

I was having a similar problem. In my case, the field was the only field in a section and the section was deemed empty/hidden until I called frm.refresh() after setting the value.

This was on v10 though.