Update docfields attributes based on workflow state


I want to change the rendering of the form fields based on workflow state.

I thought of the following.

  1. Write a js to call an api to get updated attributes for a form based on workflow state. This association of workflow state and fields attributes will be maintained in python code.
  2. Update the form via some javascript function.
  3. Validate change permitted in validate function based on data stored in db and in memory copy via json patch libs to compute diff.

So the question is

  1. Is there a better approach available?
  2. Is there a pre build function available in the framework to update attributed of form in bulk approach.
  • P.S. i am looking to change readonly and mandatory attributes.

write this in

frappe.ui.form.on("[DocType Name]", "refresh", function(frm) {