Disable editing fields in forms when there is no edit or update options

I am using the security module and this applies to forms. I tried looking in the forums but did not find this as discussion point.
When a Group Permission for a role is set to Access only and no Edit, Update or delete is enabled, the user can still edit the field. IE: The fields are not show only. When the user then clicks back they get the message “Unsaved changes will be lost. Are you sure you want to continue?” which correct if they had editing rights.
This is a problem across all forms and looking for an elegant solution as it seems that this is not function that Scriptcase Security Module caterers for.
Any suggestion are welcome.

1 Like

So in my search I think I have 2 solutions. Both work, but I think the first one is the best solution. Comments and suggestions welcome.
This is the actual first use case of the HTML Templates I found :slight_smile:

  1. In the form Layout Settings there is Header Template (Default flat). In System Layout HTML Templates I made a copy if the template and added the script to the bottom if it. Back in the form I selected the new header template and recompiled. This new template can be added to all forms
    the below should be inside the open and close script tags.

function disableFormIfNoButtons() {
var frm = document.forms[‘F1’];
if (!frm) return;

var updateBtn    = document.getElementById('sc_b_upd_t');   // Update (toolbar top)
var saveBtn      = document.getElementById('sc_b_ins_t');   // Save/Insert
var saveSelBtn   = document.getElementById('sc_b_upd_b');   // Save Selected (bulk)
var lineUpdateBtn = document.getElementById('sc_upd_line_1'); // Row update line

var updateVisible    = updateBtn && updateBtn.offsetParent !== null;
var saveVisible      = saveBtn && saveBtn.offsetParent !== null;
var saveSelVisible   = saveSelBtn && saveSelBtn.offsetParent !== null;
var lineUpdateVisible = lineUpdateBtn && lineUpdateBtn.offsetParent !== null;

if (!updateVisible && !saveVisible && !saveSelVisible && !lineUpdateVisible) {
    for (var i = 0; i < frm.length; i++) {
        frm.elements[i].disabled = true;
    }
    console.log("Form disabled because no Update/Save/Save Selected/Line Update buttons are visible");
}

}

document.addEventListener(‘DOMContentLoaded’, function() {
setTimeout(disableFormIfNoButtons, 300);
});

  1. Option 2 was to create a Internal Library with name disablebtn.php with much the same script but adding and echo and enclose the script above in the php section of the script. In the form OnScriptinit add
    sc_include(disablebtn.php, prj);
    disable_fields();
    This would need to be added to each form manually.