I’m trying to get most fields in a form non-editable, except for some.
For example, once an invoice has been created, only the stop and start date should still be changeable.
I have tried at first to set the entire record to readOnly but this does not seem to work as you can not override it for the fields.
I was then thinking of the following code:
if ((invoiceid) && (globals.group != 6)) {
plugins.dialogs.showErrorDialog(‘ERROR’, ‘This SR has been assigned a number and can not be changed.’, ‘OK’)
immocontract_start = oldValue
}
But I am unsure how to retrieve the value before edit.
Is this possible?
Other option would be to loop through all the fields but for some reason I can’t seem to write a piece of code which succesfully puts all of them on readonly/non-editable
is it using smart or web client?
using the form elements array, you can easily make all of them read-only with a simple loop.
you could try to find a trick to save the former value and restore it, but this upsets users most of the time.
the best is (for me) to use a separate colour for editable fields. in form mode, this can be linked to the field content.
if you don’t like a different backgroung, a different border is quite smart.
exact, only named elements will be present, so check if all of them have a name.
and to split field from buttons, you can test each with “getElementType()” or name field elements with a prefix and test it, either way will work.
example with prefix “field_”:
for (var $i=0 ; $i < elements.allnames.length ; $i++)
{ if ( utils.stringLeft(elements.allnames[$i],6)==“field_”) elements[elements.allnames[$i]].enabled = false ;
}