ReadOnly field using java script (value disappear when field changed to ReadOnly)

I have a  field as Editable. The field is automatically populated with the value when the page is loaded. I have a condition to make filed readable using javascript. If the condition  satisfied, the field changed to Read only but the value disappear,  Below is the code to make field Readlonly,

var modRef =skuid.model.getModel(‘PayInv’);
var rowRef = modRef.getFirstRow();
var f = rowRef.Refunded_Amount__c;

console.log(f);
    if(newD !== dateString)
    { 
        f.readOnly = true;
    }

I am wondering why the value disappear when the field changed to ReadOnly ? I would be glad if any one could help me with this.

HI Amish, I may not be able to provide the full answer on this one, but have had experience with this before so I wanted to provide my knowledge of this so far. I believe this is because the value hasn’t been saved to Salesforce and only resides in Skuid customization’s until you would save…especially since you say it defaults in on page load. I have also noticed that if you try to see a value of a field that isn’t saved in a Read-Only state on a layout you can’t see the value you set, but once you save the field value is shown. Maybe another community member has ideas on how to extend this with javascript, but if I think of another way around it with a UI only field or template field I’ll let you know. :slight_smile: Thanks, Jeff

Hello Jeff,
                Thank you for the quick response. When I do console.log() , it still shows the value on console but not in skuid page ?? Is it something to do with “saving” ?

Amish, No problem! To my knowledge you are setting it in the Model values on the page to some degree, but the model doesn’t show the value until it is saved to the database. This has been my experience so far and usually I have been able to hide the field value from the layout and use a wizard approach. For example I would make the first step in the wizard where it lets you enter all the details (hiding the read-only field you technically are setting through JS and then a second step to review the saved details and make changes if necessary…at which point I see the read-only field completed. Not sure if that fits your use case, but it is something I like doing and gets around that issue for me normally. Thanks, Jeff

Hello Jeff,
                    Thank you ! I will try this approach and let you know.
Thank you !