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

Conditioning elements on a table.

Discussion in 'Community' started by alekimn, Nov 28, 2021.

  1. alekimn

    alekimn New Member

    Level: Community
    I have two forms and i want to set them, that the conditions of form A, determines the display and input of form B.
    like this...
    Form A has an element with 3 dropdown. Form B has an element with a textbox. If a user chooses option one on the element in form A, the text box in form B, will disappear or change to read only. If the user chooses option 2 and 3 on Form A, the textbox on Form B can be edited.
    I created both forms on a single database table, but the problem is that the JavaScript option(ready made ones) is not selecting elements on a dbtable, but is selecting elements in the same form, means i cannot set condition on elements in another form, despite sharing the same table.
    I'm not a coding expert that why i need your help.
     
  2. deant

    deant Active Member

    Level: Community
    Last edited: Nov 28, 2021
  3. alekimn

    alekimn New Member

    Level: Community
    ok. Thats still a great idea, but here is the real scenario.

    Code (Text):
    Form A               Form B
    (dropdown)            (text area)
    element 1            element 1(b)
    element 2            element 2(b)
    If user selects value 1 on element 1, then element 1(b) turns to read only. And if user selects option 2 and 3 on element 1, then element 1(b) can be edited.
    The code should be run on every element of the form and i need a help on that code.
     
  4. alekimn

    alekimn New Member

    Level: Community
    I've tried on my own but oops...
     
  5. troester

    troester Well-Known Member Staff Member

    Level: Community
    Not sure what you mean with "If user selects value 1... then 1(b) turns to readonly..."
    If these are 2 independent forms the user doesn't select anything at this moment but somebody selected value1 and this was stored in the DB.

    And what do you mean with "The code should be run on every element of the form"?
    Should the complete form B be readonly if the dropdown in FormA has value1?

    "despite sharing the same table." So you have a list A and a list B linked to the same DB table?

    You could create a (hidden, readonly) element in list B linked to the column storing the dropdown from your listA.
    This can be accessed via JS.
    But following your description I have the feeling your are looking for something like the canEditRow list plugin.

    BTW: Hiding (or making readonly) via JS is never a security means, a user can skip it. So if you have a editable element which must not be edited you must add a php validation (or a php form plugin) to "undo" editing if a user did so.
     
  6. alekimn

    alekimn New Member

    Level: Community
    I'll try to use the js as you have said, , but to clarify things where you don't understand,
    Here are the screenshots of the forms
    Form A
    Screenshot_20211130-054244.jpg
    drop-down selection on Form A

    Screenshot_20211130-054731.png
    Form B
    Screenshot_20211130-054310.jpg
    They have same label(easy to differentiate), but different names, for dbtable.
    if i choose "no change", in form A then i cannot edit that section on form B, but if i choose others, then i can be allowed to edit that section.
    And that should go on to other elements. The values of drop-down are -1,1,2,3 respective.
    Thanks..
     
  7. alekimn

    alekimn New Member

    Level: Community
    Hi..
    I came up with a better method(according to me) but I made things worse. I created a different dbtable for form B. I then created another table, and copied elements from form A and B, except id, date and time. I was trying to join the tables tongether, but i didn't complete.
    I got an error on the browser and i cannot be able to edit the form anymore...
    I was thinking of deleting the list and creating a new one, but i think i'll still encounter the same problem. How can i bypass this, please.
     
  8. juuser

    juuser Well-Known Member

    Level: Community
    Can you access your backend and remove the join you made?

    To be honest I also don't get what exactly are you trying to achieve.

    From your last post I assume you had Form A and Form B referring to the same db table. So you get the same data from database when editing either form.

    Or are you showing some elements in Form B which are not visible in Form A and vice versa. In that case you can hide elements with element js on load and "if some element value = something, hide another element".

    But like @troester said, elements hidden by js can be unhidden by malicious users, so if there's a change it could happen, you should add extra php-validation to hidden elements.
     
  9. alekimn

    alekimn New Member

    Level: Community
    Ok. One more Question. How can i append a unique id on a form during redirection to another form.
    I mean redirecting from Form A to form B. Here is what i found while i was searching but i cannot understand how i can i append id from form A into form B id field without knowing it.
    Forms | Fabrik (fabrikar.com)
     
  10. alekimn

    alekimn New Member

    Level: Community
    Honestly, @juuser and @troester I didn't know how to use js, back there, but after a dozen times of creating and dropping tables, installing and uninstalling fabrik, now i have the form working.
    Thanks for your help and time.. I hope i'll also help someone with this type of problem someday..
     

Share This Page