user can edit element if empty

Hi,

On our website, when a company creates a customer, on another list there is a new record created. For now, only the id, the date and the customer name is inserted in the new list.

There are several other elements what the company can fill in when editing the new record.

Now there is one element called "code". When the record on the new list is created this element is empty. So, when a company opens the record, its possible to add a value to the mandatory element "code".

Now I want, when a company has given a value, and saves the record, the next time when editing the record this element cannot be changed anymore.

Now, the normal settings when a user adds a new record by clicking "ADD" in the listview can be set by adjusting the "userrole permissions" So who can add, edit, view or delete rows.

When i say userrole company can add .. but only superuser can edit, its working by adding a new record/row.

But, since the record is created by another list, this permission settings is not working. Because, there is a new record in the list, what a company has to edit, so it is not possible to give a value in the "code" element.

So, how can I set it like, if element is empty, user can give a value. If value is saved, then user cannot change value anymore.

Its a bit difficult to explain in English but i hope you understand.

Regards Jap
 
If "safe" enough for your use case, the simplest way I can think of is using Javascript: if the element is not empty, hide or disable it or set it to readonly -- whichever works best for you.
Of course, you want to set the ACL for edit back to public or whatever you need (but not Super Users).
 
You can add the JS + a php validation checking if original value=submitted value (in case the user tried to hack the form
 
Sorry it took so long to answer your replies. It was very busy at my side.


If "safe" enough for your use case, the simplest way I can think of is using Javascript: if the element is not empty, hide or disable it or set it to readonly -- whichever works best for you.
Of course, you want to set the ACL for edit back to public or whatever you need (but not Super Users).

Ok, I tried to do this, but I do not know how to get " Is empty" Can you point me in the good direction?

Screenshot_43.png

You can add the JS + a php validation checking if original value=submitted value (in case the user tried to hack the form

This is a good one. To be honest I have no Idea about how to achieve this. I really hope you can tell me more, about what i do have to fill in or write to achieve this.

Screenshot_44.png

I did googling for a long time, but couldnt find anything what could help me. Normally I can do a lot with googling and this forum but in this case, I am stuck.

Hope that you can help me

Regards!
 
Your element JS settings look ok, just make sure you add this to id-element not the code-element.

About the php validation, you need to get the old and new value and compare them, something like this:
Code:
$origData = $formModel->getOrigData();
$oldvalue = $origData[0]->table___element_raw;
$newvalue = '{table___element_raw}';
return $oldvalue == $newvalue;

or the old value might also be without "[0]": $oldvalue = $origData->table___element_raw;

Do a "var_dump " to see the actual values if needed.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top