Is there a way to lock a field when a button is clicked so that no one can change values in the fields accidentally but when a button is clicked they can type new values or change the value of a field?
Or you can set a validation field option:
Not IsEmpty ( LockField )
If there is a value in LockField all attempts to modify the field will trip a validation error. Thus, you can set up a check box format on the lock field and click it once to lock the field, click it again to unlock it. Unlike the script trigger method, this will protect the field on all layouts and will also prevent drag and drop actions from modifying the field.
But the script trigger method can be much more user friendly as it prevents the user from even trying to modify the field where the onObjectModify option allows the user to modify the field, then rejects the modifications with an error message.
In some cases, I've actually used both methods for the same field for that reason, using the trigger to keep things as user friendly as possible while keeping the validation option in place as added "insurance" against accidental change.
PS. and another method that I have used on the Tutorials layout in the Known Bugs List is to use script triggers that detect a change to the value of the field and ask the user if they want to save the change or revert the field to its original value.
You can use a script trigger use OnObjectEnter to test if the field is Editable and if not go to the next field.
Retrieving data ...