1. NOTICE: If you are using Fabrik and update to Joomla 3.10, you will need to update to Fabrik 3.10. And, if you are using Fabrik, do not upgrade to Joomla 4, we do not have a supported version ready for release. More information on a release date coming soon. Also, please note that Fabrik 3.10 will not install on any Joomla sites less than 3.8.
    Dismiss Notice

user can edit element if empty

Discussion in 'Community' started by Egocentralis, Sep 25, 2021.

  1. Egocentralis

    Egocentralis Member

    Level: Community
    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
     
  2. lousyfool

    lousyfool Active Member

    Level: Community
    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).
     
  3. troester

    troester Well-Known Member Staff Member

    Level: Community
    You can add the JS + a php validation checking if original value=submitted value (in case the user tried to hack the form
     
  4. Egocentralis

    Egocentralis Member

    Level: Community
    Sorry it took so long to answer your replies. It was very busy at my side.


    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

    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!
     
  5. juuser

    juuser Well-Known Member

    Level: Community
    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 (Text):
    $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.
     

Share This Page