1. Fabrik 3.8.1 has been released. It is mostly bug fixes and feature enhancements, but does include two new plugins (push notifications, and the sequence element). As usual we strongly recommend testing the new release on a sandbox if your application is mission critical, and always do an Akeeba backup before updating.

Checkbox element - how to make no checkboxes until user adds them

Discussion in 'Standard Support' started by Bren, Apr 17, 2017.

  1. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    Not sure what you mean by this. How are you picturing that, in list view? In read-only contexts, we just display an unnumbered list (UL) of the selected labels. Not sure how we'd represent un-checked ones.

    -- hugh
     
  2. Bren

    Bren Member

    Level: Standard
    Hi Hugh.
    Yes, it’s an odd question; but the application makes sense. The correct DJoin checkbox labels list appropriately in the list; but only if they are checked in the related form. If they are unchecked then they vanish from the parent list. The problem is that others users want to be able to always see the PO#s (labels) in the list weather they are checked or not. They want the check box beside each label in the form to represent that the related material delivery for each checked off PO# (label) has arrived and not weather it appears in the parent list or not. Does that make sense and, if so, can it be done?
    Thanks in advance.
     
  3. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    I can't think of a way of doing that with the join element. Can't even do it with layout overrides, as the join element is one of the few that doesn't have it's own list layout, it uses the generic element model one, and by the time that layout is run, the non-selected label data is gone.

    The only way to do it would be with some custom code, either in a custom template, or maybe a calc element. The calc element would have to query the join table, get all the labels, and render them. Then you could display the calc instead of the join element in the list.

    -- hugh
     
  4. Bren

    Bren Member

    Level: Standard
    Cool. I knew you would have a good direction to send me. I’ll give it a try.
    Thanks Hugh. I appreciate it.
     
  5. Bren

    Bren Member

    Level: Standard
    Hi Hugh. Any chance you can share a generic sample of the php code for me to add within the calc element settings?
    Thanks in advance.
     
  6. Bren

    Bren Member

    Level: Standard
    Hi Hugh. I tried using the calc element; but for some reason I was getting an error page. So, I switched it to a display element instead and turned on Eval. So, the furthest I got was replicating what the DBjoin was doing on the list using the following in the display element default setting.
    Code (Text):
    return '{bw_projects___po_checklist}'';
    So, next I need to do the "query the join table, get all the labels, and render them" part that you recommended. This is where I could use some help or an example.
    I took a look at the Common PHP Tasks and I think I need to do the portion that says the following.
    If so; I could use some clarity on the specifics. For instance, can "$row = $listModel->getRow($rowId);" be used in this case instead of all of the above? If so, do I then return $row? I apologize for maybe asking some basic stuff; but I couldn't find a real example in the forums that I could substitute with my real table, field, list and element names. Sometimes I just need it as clear as speaking to a 5 year old, LOL.
    Thanks in advance and I hope to hear from you soon.
     
  7. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    I just read the whole thread again, and if I'm understanding correctly, the selections you want to show from the other table are where 'fid' is the foreign key (points to the rowid id of the main form).

    Code (Text):

    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $myQuery->select('your_label_element')->from('the_other_table')->where('fid = "{rowid}"');
    $myDb->setQuery();
    $myResults = $myDb->loadColumn();
    if (!empty($myResults)) {
       return '<ul><li>' . implode('</li><li>', $myResults) . '</li></ul>';
    }
    return '';
     
    Obviously replace the field and table names int he query as appropriate. That should return a list (UL) of the labels.

    -- hugh
     
  8. Bren

    Bren Member

    Level: Standard
    Hi Hugh.
    I tried your suggestion with the following; but it generated an error right away when I brought up the list.
    Code (Text):
    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $myQuery->select('bw_projects___po_checklist')->from('bw_projects_repeat_po_checklist')->where('fid = "{rowid}"');
    $myDb->setQuery();
    $myResults = $myDb->loadColumn();
    if (!empty($myResults)) {
       return '<ul><li>' . implode('</li><li>', $myResults) . '</li></ul>';
    }
    return '';
    Then I looked back on what I wrote earlier in this thread; especially when I was wondering where the fid variable came from. The problem is the fid only gets saved when a form is opened in the form php plugin. I only have this display element visible on the list. The point is to list all of the DBjoin items in each record within the parent list; regardless if they are checked or not. So, not sure if I also need to generate a fid variable with maybe a php list plugin to make this work? Or, maybe I'm not looking at this right? Any suggestions?
    Thanks in advance and I hope to hear form you soon, Hugh.
     
  9. Bren

    Bren Member

    Level: Standard
    Friendly bump.
    Thanks in advance.
     
  10. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    I've just totally lost the plot on what's what in your setup.

    Maybe try 'parent_id' instead of 'fid'.

    If that doesn't work, we may just have to do this as a small piece of billable work. There's a limit to what I can do in the forums, especially when it comes to this kind of looong thread where I can't see what you are actually trying to do, and writing code becomes an exercise in guesswork.

    -- hugh
     
  11. Bren

    Bren Member

    Level: Standard
    Hi Hugh. I took a better look at your recommendation and realized I was applying it wrong. I revised the calc element PHP to the following and it worked!
    Code (Text):
    $myDb = JFactory::getDbo();
    $myQuery = $myDb->getQuery(true);
    $myQuery->select('po_number')->from('bw_pos')->where('fid = "{rowid}"');
    $myDb->setQuery($myQuery);
    $myResults = $myDb->loadColumn();
    if (!empty($myResults)) {
       return '<ul><li>' . implode('</li><li>', $myResults) . '</li></ul>';
    }
    return '';
    This calc element also is nicely hidden in the form and my DBjoin with checkboxes is displayed. So, it works; until I click on the save button in the form and the attached/following error page appears:
    Not sure why. If I unpublish the calc element then there error page goes away. I'm so close and I'm hoping that you'll notice something obvious that I'm missing hear. Any suggestions?
    Thanks in advance.
     

    Attached Files:

  12. Bren

    Bren Member

    Level: Standard
    Hi Hugh.
    I’ve been searching the forum threads trying to find an answer to my last error and I came across one where you recommended a solution using a PHP form plugin that would update a regular field element with data; per the following.
    Instead of trying to solve my last error with the calc element; I’m wondering if I should abandon the calc element and do something similar. If this sounds like it would work; should I use a textarea element versus a regular field element because of the possibility of displaying a long unordered list? Any suggestions?
    Thanks in advance and I hope to hear from you soon.
     
  13. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    That error looks like a join element adding a filter query when building a list filter.

    Do you have any "filter queries" on bw_projects_repeat_po_checklist?

    -- hugh
     
  14. Bren

    Bren Member

    Level: Standard
    Hi Hugh.
    Not sure. The bw_projects_repeat_po_checklist table was automatically created by Fabrik when I created the bw_projects___po_checklist DBjoin element. Is the "filter queries" setting within bw_projects___po_checklist DBjoin element? If so; could I trouble you to share where within I would find this setting?
    I only found the "Include in list query" setting in "List view settings > List settings tab"; which it was on and I turned it off. I also changed the "Filter Type" setting to "None" in the "Filters" tab. I then tested and had the same error page only when I press the form submit button. If I close the page and reopen in the related list then everything looks fine. Maybe I'm looking in the wrong place...
    Or, maybe you meant what we added in the "Details > Data - where" at the beginning of this thread within the bw_projects___po_checklist DBjoin element (see the attached snippet)?
    Thanks in advance.
     

    Attached Files:

    Last edited: Jun 14, 2018
  15. Bren

    Bren Member

    Level: Standard
    Any suggestions on where I could find the “filter queries” setting?
    Thanks in advance.
     
  16. cheesegrits

    cheesegrits Support Gopher Staff Member

    Level: Professional
    Which site is this on? I checked the one in your My Sites, but that doesn't seem to be the right site.

    -- hugh
     
  17. Bren

    Bren Member

    Level: Standard
    Hi Hugh.
    I'll clone the site and redo mySites again tomorrow. I'll let you know when its ready.
     
    Last edited: Jun 18, 2018 at 3:03 AM
  18. Bren

    Bren Member

    Level: Standard
    Hi Hugh. OK, sorry for the delay. It's been a really busy week. I finally cloned my live site to mySites. If there's any way you could take another look into this it will be greatly appreciated. I feel it's so close because it works; but just creates that error page every time the form submit button is pressed during a form edit & not a form add/new (only if the "bw_projects___po_checklist_listonly" element is published). I added a new job (site name) record to the material shelf page "Test site 1" and I added a couple PO checklist numbers; which appear in the list correctly and also the form correctly. It just took an error page, closing the web page and reopening to the list to get it there.
    Thanks in advance, Hugh.
     

Share This Page