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

when a list is displayed on form, methods for handing form saving

Discussion in 'Professional Support' started by skyrun, Sep 12, 2018.

  1. skyrun

    skyrun Active Member

    Level: Professional
    i have a list displayed on a form (through the content plugin).

    only problem is that if i click to display, edit or add to the list, then the browser does that and doesn't save any changes i may have made to the form first.

    here are three approaches i have considered to solve this that i am wondering if are possible on fabrik (i'm sure there are other approaches):
    1. display the add/edit/details for the embedded list in a modal box over top of the form so the form/DOM is still intact underneath.
    2. make the add/edit/details links on the embedded list open in a new tab.
    3. have fabrik ask 'Save changes to [form name]?' before going off of any form on any page. This seems like a good enhancement all around. An 'are you sure' when leaving the page if you leave it using the window.xxxx method or the user changing the url on the page vs. when the user presses a button like save or 'go back' on fabrik. wouldn't even have to check to see if there were changes, could do it every time you are leaving a form page in a 'forced' way.
    i don't know how to implement any of these 3... any recommendations?
  2. troester

    troester Well-Known Member Staff Member

    Level: Community
    for 1.
    Did you try a list with ajaxfied links? This should open add/edit/details in a popup.
  3. skyrun

    skyrun Active Member

    Level: Professional
    yes, i have ajaxified links set to yes on the list that is displayed within the form. however when the list is displayed that way, it does not work. no .js, but does nothing (ie it opens in the same tab vs. a modal box when you click +add/edit etc as if ajaxify were set to no)

    also note that if i open the list natively (ie not on the form) that it does work. it even updates the list on the screen after adding and editing. so it's the perfect solution for this but doesn't seem to function when run on a form OR when run from the content plugin (which is how i include it on the form.

    if you have the fabrik logon for my devl site, you can see this here:
    on the 'notes' tab.
    Last edited: Sep 13, 2018
  4. troester

    troester Well-Known Member Staff Member

    Level: Community
    I just tested and it's working fine on my site.

    List links ajaxfied, list in form intro, Protostar template.
    I can put text is form fields, add/edit/display list records -> the edited form fields are still showing the new text and the form can be saved.

    I can't log in on your testlocation.
    Where did you put the content plugin? With a standard list template (using the <form tag) you can only put it into intro/outro.
  5. skyrun

    skyrun Active Member

    Level: Professional
    i wanted the list on a new tab, so i have included it in the template. i couldn't figure out how to add a tab (which is a group for the other 4) without adding html to the form template.

    so at the end of my template, i added this:

    Code (Text):

    // BVC ADD NEW TAB for notes list
        $tabId = $this->form->id . '_' . (int) $this->rowid . '_' . $i;
        $notestabId = $tabId;
        $is_err = false;
        $tab = new stdClass;
        $tab->class = $i === 0 ? 'active ' . $err_class : $err_class;
        $tab->css = $group->css;
        $tab->href = 'group-tab' . $tabId;
        $tab->id = 'group999_tab';
        $tab->label = 'Notes';
        $tabs[] = $tab;
    // BVC END ADD

        echo FabrikHelperHTML::getLayout('fabrik-tabs')->render((object) array('tabs' => $tabs));
  6. troester

    troester Well-Known Member Staff Member

    Level: Community
    So where are you loading the content plugin?
    I assume somewhere after the 2nd loop (tab-content)?

    As I've said:
    You can't load a list inside the form's <form tag, i.e. you can't load it between line 42 to 156 in bootstraps_tabs/default.php
    because this will create nested form tags (the list template is also doing <form>...</form>)
    which will break the whole thing.
  7. skyrun

    skyrun Active Member

    Level: Professional
    ok. getting closer.

    yes, i had this a little farther down:
    Code (Text):

                // next part, add content to notes tab
            <div role="tabpanel" class="tab-pane" id="group-tab<?php echo $notestabId; ?>">
                <fieldset class="tabpane" id="group999_tab" style="">
                    <legend class="legend">Notes</legend>
                    {fabrik view=list embeddedForm=1 id=177 srms_work_order_notes___wo_id=<?php echo $this->rowid; ?>}
            <?php // end addition    ?>
    <?php if ($model->editable) : ?>
        <div class="fabrikHiddenFields">
            <?php echo $this->hiddenFields; ?>
    echo $this->pluginbottom;
    echo $this->loadTemplate('actions');
    <?php // was </form> no php ?>
    echo $form->outro;
    echo $this->pluginend;
    echo FabrikHelperHTML::keepalive();
    in this hack-attempt, i commented out the </form> that was at the end of the loop and added it up after the 4th tab and now the 'add' button opens the form in a modal window, but the form no longer works adn there are no save buttons showing on the modal window.

    that's because the buttons at the bottom are outside of the loop of course and are no longer in the </form>.

    knew better, but tried anyway to end the form with </form>, display the new list and then start a new <form>. but that yielded an invalid token error message.

    so i don't think it's going to be possible to include the list on a tab on the form since there is no way that i can think of to have the list be on a tab that is on the form and also outside of the oveall <form></form>
  8. skyrun

    skyrun Active Member

    Level: Professional
    trying to figure out if it can be done in an iframe somehow...

    running into an issue embedding the content plugin within an iframe. trying:
    Code (Text):
    <iframe src="data:text/html,{fabrik view=list id=177 srms_work_order_notes___wo_id=<?php echo $this->rowid; ?>}"></iframe>
    but it's not working... its loading the list html because the intro is showing (not correctly utf-8 encoded). but there are encoding issues or something... looks like this:
    so let me know if you have any ideas to display a list within a form and still allow the ajaxify links.
  9. skyrun

    skyrun Active Member

    Level: Professional
    another note. when i put the lists in the outtro (i assume same as 'footer' on the form), the EDIT button does work correctly to ajaxify, but the '+add' button still displays in the same window.

    any other ideas to be able to have a list in a form that doesn't mess up the saving of the form?

Share This Page