• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Form cancel button

jo-ka

Member
Hello,

I know I can add a back button on Forms, but is there a way to have a CANCEL button, this is, clicking there would take user back to where he came from, for example a list.

I've noticed that the back button is doing exactly what it have to do, going back, but if the form is refreshed some times, going back is not exactly the same as cancel, or close, or exit without saving, for example.

How can I do this?

Thanks in advance.
 
Nope, there's no specific Cancel button. It is possible to add a custom button, by overriding the form/fabrik-custom-button.php layout. See wiki for where to put it.

-- hugh
 
OK, I ended up doing this without JS, with this code:

<?php
if ($d->formModel->getId() == 14) {
?>
<a class="btn btn btn-secondary" href="index.php?option=com_fabrik&view=list&listid=14" role="button">Cancelar</a>
<?php
}
?>

I wonder, is there any way to replace the Form ID (14) with something like {thisform}? This way I could create a generic cancel button withou the need to identify each form...
 
Well, you can get the list ID ...

Code:
<?php
$listId = $d->formModel->getListModel()->getId();
$listURL = JRoute::_('index.php?option=com_fabrik&view=list&listid=' . $listId);
?>
<a class="btn btn btn-secondary" href="<?php echo $listURL; ?>" role="button"><?php echo JText::_('COM__FABRIK_CANCEL'); ?></a>

Also added creating route (so SEF'ed link if you use them), and translating the default COM_FABRIK_CANCEL language.

-- hugh
 
Last edited:
Well, you can get the list ID ...

Code:
<?php
$listId = $d->formModel()->getListModel()->getId();
$listURL = JRoute::('index.php?option=com_fabrik&view=list&listid=' . $listId);
?>
<a class="btn btn btn-secondary" href="<?php echo $listURL; ?>" role="button"><?php echo JText::_('COM__FABRIK_CANCEL'); ?></a>

Also added creating route (so SEF'ed link if you use them), and translating the default COM_FABRIK_CANCEL language.

-- hugh
Tried this and got this error:

Parse error: syntax error, unexpected '(' in/home/xxxxx/public_html/suporte/components/com_fabrik/layouts/form/fabrik-custom-button.phpon line26

This is this line:

PHP:
$listURL = JRoute::('index.php?option=com_fabrik&view=list&listid=' . $listId);

Tried to change the code to (don't really know the sintax):

PHP:
$listURL = JRoute::_('index.php?option=com_fabrik&view=list&listid=' . $listId);

And got another error:

Fatal error: Call to undefined method stdClass::formModel() in/home/xxxxx/public_html/suporte/components/com_fabrik/layouts/form/fabrik-custom-button.phpon line25

What can be wrong?
 
I didn't try.
But if your first code
<?php
if ($d->formModel->getId() == 14) {
?>
is running correctly
I assume the part Hugh gave you should be

$listId = $d->formModel->getListModel()->getId();

(i.e. formModel without () )
 
Thanks troester. That's it!
So the code must be
PHP:
<?php
$listId = $d->formModel->getListModel()->getId();
$listURL = JRoute::_('index.php?option=com_fabrik&view=list&listid=' . $listId);
?>
<a class="btn btn btn-secondary" href="<?php echo $listURL; ?>" role="button"><?php echo JText::_('COM__FABRIK_CANCEL'); ?></a>

This is, on first line formModel-> without () and on second line, the need to add the underscore after JRoute, so JRoute::_(

So, just to finish. Is there a way to have an event, when clicking Cancel button, saying something:

Do you really want to exit without saving?

Javascript? Form plugin? I now there's a confirmation form plugin, but that's for save button (submit) only, right?

Thanks in advance.
 
Sorry about the typos. I've fixed the post to correct them.

To add a confirmation, add an onclick event on the ...

Code:
<a class="btn btn btn-secondary" href="<?php echo $listURL;?>" role="button" onclick="return confirm('Are you sure?');"><?phpecho JText::_('COM__FABRIK_CANCEL');?></a>

If you want to make the string translated, add a language override for it in J!, and do ...

Code:
<a class="btn btn btn-secondary" href="<?php echo $listURL;?>" role="button" onclick="return confirm('<?php echo JText::_('YOUR_CUSTOM_CONFIRM_LANGUAGE_STRING'); ?>');"><?phpecho JText::_('COM__FABRIK_CANCEL');?></a>

-- hugh
 
OK, Perfect.
One final question:

How can I control the buttons location? For example, on cell phones the result is this:
upload_2018-1-25_8-54-9.png
On laptops, the result is this:
upload_2018-1-25_9-3-17.png

Is there a way to have something like this?
upload_2018-1-25_9-3-56.png

Probably I need to change on custom.css for laptops, but for cell phones?
Thanks in advance.
 

Attachments

  • upload_2018-1-25_9-2-11.png
    upload_2018-1-25_9-2-11.png
    4.5 KB · Views: 13
  • upload_2018-1-25_9-3-47.png
    upload_2018-1-25_9-3-47.png
    4.5 KB · Views: 15
The buttons are displayed in your form template in default_actions.php and has a "hardcoded" layout:4 cols, 2 cols, offset1 (only bootstrap2 I think), 2 cols, offset1, 4cols-pull-right (which is 14 cols?:confused:).

So you can try to tweak the classes via custom CSS (e.g. overriding the .offset1, .span2, .span4 ...) or create a custom template and edit the classes directly.
 
Last edited:
OK, thank's.
So I ended up changing default_actions.php and get this results, which are pretty close what I need:

upload_2018-1-25_14-37-49.png
The question is: When I update Fabrik, does this file (default_actions.php) will be changed also to it's default state?
If so, do I need (and how, point me to Wiki if so) to create a custom template?

Thanks in advance.
 
Default Fabrik templates will be overridden, yes.
To create a custom template just copy the folder (e.g. bootstrap), rename it to e.g. mybootstrap, select this folder in form Layout settings.
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top