1. Fabrik 3.9 has been released. If you have updated Joomla to 3.9, this is a required update.
    Dismiss Notice

Showing or Hiding a Field Based on Dropdown Choice of another Field

Discussion in 'Community' started by Stranger, Jul 13, 2019.

  1. Stranger

    Stranger New Member

    Level: Community
    What I want to do is simple. Based on the choice made on a dropdown field (e.g., country: 1. USA or 2.Canada)
    I would like to show the relevant address field (zip code for USA or postal code for Canada) and hide the irrelevant one. I researched old posts and I think the following post is the closest match to my need:

    http://fabrikar.com/forums/index.ph...eld-elements-based-on-parent-selection.43461/

    If I understand correctly, I will have to go to the Country field, navigate to options, and then add JS code to do that. The difference from the post above, however, is that I do not need to create a separate group within the form. I also do not know much JS, unfortunately. So if anybody can help with adapting the solution above to my simpler situation and with the JS code, I will be grateful.

    Thanks in advance.
     
  2. lousyfool

    lousyfool Active Member

    Level: Community
  3. Stranger

    Stranger New Member

    Level: Community
    Thank you. In principle that should probably work. However, when doing this I am getting error 500 alter structure: Duplicate column name 'country'. I think the problem is that when Fabrik generates the JS code based on the predefined JS actions it is not appending the table name to the column name (e.g., table_name.country) and SQL is at a loss as to which table the column 'country' belongs. Does anybody know of a way to fix this?
     
  4. lousyfool

    lousyfool Active Member

    Level: Community
    Have a screenshot of your settings?
     
  5. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    When do you get that error? It says "alter structure", which should only happen when you make changes on the backend that involve changing the database structure itself (like changing an element name or type, that involves making a change to the table structure itself).

    -- hugh
     
  6. Stranger

    Stranger New Member

    Level: Community
    From what I understand this is a common error that people get when upgrading to a new Joomla! version. What is recommended in this case is using the database Fix tool which I did, yet the error persists.

    I have not knowingly altered my database tables in any way, save for adding a Fabrik element or changing the order of elements.
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    You didn't answer my question.

    -- hugh
     
  8. Stranger

    Stranger New Member

    Level: Community
    Excuse me. I focused on the latter part of your post. I get this error when going to the JavaScript of my element and trying to save a predefined action, which in this case is: upon event "select" show the field "zip_code" which is defined as hidden by default. When I click "save and exit" I get this error and of course the action is not saved.
    I hope this answers your question.
     
  9. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Yup, it does.

    Do you get the same problem if you make any other changes to the element?

    I can't think of anything that setting a JS action does that could cause any confusion about field naming.

    The only time I've seen anything weird happen with setting JS actions is when setting a lot of actions, and the number of HTML form elements being posted exceeds PHP's configured maximum.

    -- hugh
     
  10. Stranger

    Stranger New Member

    Level: Community
    Thank you Hugh. I never actually thought of doing that. Simply trying to "save and exit" after opening the element without even doing any changes to it gives me the same error. So this obviously is a database error not a Fabrik error. And it seems to be just this element: I have tried other elements and they "save and exit" without problem.

    The problem is still unsolved. At lease we do know now that it is purely a database problem.
     
  11. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Try deleting and retyping the element name (not label). It's possible you've gotten some non printing characters in there, or maybe a trailing space.

    -- hugh
     
  12. Stranger

    Stranger New Member

    Level: Community
    I finally figured it out. I post the solution here in case somebody else encountered a similar problem in the future. The problem was exactly what the (typically cryptic) error message said: a duplicate column name. Not in the same table, mind you. I had completely forgotten that I had a separate table for countries and in it was a field named country. When I changed the name of the field that is causing me trouble slightly the problem disappeared. I still think that this shouldn't have been a problem in the first place since the identical names were in two separate tables, but who knows what a database inner workings are like. Anyway, if the problem is solved, I am happy.

    Thanks a bunch to lousyfool for drawing my attention to predefined javascript actions and to Hugh who helped me correct my investigation focus. People of the Fabrik community: you are the best.
     
    lousyfool likes this.
  13. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Community
    Same name in a different table should have no effect, and I've never seen anyone have that error before. So something wierd in your setup.

    -- hugh
     
  14. Stranger

    Stranger New Member

    Level: Community
    The only thing I can think of is that in the Country table the column "country" is key. I am not sure whether that had an effect on what was going on.
     

Share This Page