# Non-editable fields in a record

**URL:** <https://forum.servoy.com/t/non-editable-fields-in-a-record/11711>\
**Category:** Classic Servoy\
**Created:** [February 4, 2010, 11:20am UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711 "2010-02-04T11:20:35Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![JohnCorb](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@JohnCorb](https://forum.servoy.com/u/JohnCorb)\
**Post date:** [February 4, 2010, 11:20am UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711/1 "2010-02-04T11:20:35Z")

</div>

Hi guys,

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

Thank you for your feedback.

Kind regards,  
John

---

<div class="post-metadata">

**Author:** ![lesouef](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lesouef](https://forum.servoy.com/u/lesouef)\
**Post date:** [February 4, 2010, 11:46am UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711/2 "2010-02-04T11:46:26Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![JohnCorb](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@JohnCorb](https://forum.servoy.com/u/JohnCorb)\
**Post date:** [February 4, 2010, 12:04pm UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711/3 "2010-02-04T12:04:38Z")

</div>

Hi,

it is in the SmartClient.

I am sorry but I am having difficulty creating this code.

Could you provide me with a example?

Many thanks,  
John

---

<div class="post-metadata">

**Author:** ![JohnCorb](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@JohnCorb](https://forum.servoy.com/u/JohnCorb)\
**Post date:** [February 4, 2010, 12:06pm UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711/4 "2010-02-04T12:06:45Z")

</div>

I had already considered looping through the elements but all my fields are not present in the elements array.

The buttons are.

---

<div class="post-metadata">

**Author:** ![JohnCorb](https://avatars.discourse-cdn.com/v4/letter/j/958977/32.png) [@JohnCorb](https://forum.servoy.com/u/JohnCorb)\
**Post date:** [February 4, 2010, 12:11pm UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711/5 "2010-02-04T12:11:11Z")

</div>

I think I realise what the previous designer did wrong.

It’s always useful to name your elements…

---

<div class="post-metadata">

**Author:** ![lesouef](https://avatars.discourse-cdn.com/v4/letter/l/7993a0/32.png) [@lesouef](https://forum.servoy.com/u/lesouef)\
**Post date:** [February 4, 2010, 1:26pm UTC](https://forum.servoy.com/t/non-editable-fields-in-a-record/11711/6 "2010-02-04T13:26:08Z")

</div>

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 ;  
}
