• 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.

Add Custom Button next to Submit

nbradshaw

Active Member
I would like to add a button called "Submit For Approval" next to the Submit button.

Submit button will just do the submit action.
"Submit For Approval" will submit + change an element to = 1

Is there an easy way to do this?

Thanks
 
Define "easy". I think the answer is "no". It's not rocket surgery, but not a one-liner either.

I just committed something to make it slightly easier, which is a new layout you can override (fabrik-custom-button). But you'd still have to write some JavaScript to set the element value.

So you'll need a ./component/com_fabrik/js/form_X.js (where X is your numeric form ID), with something like .

Code:
requirejs(['fab/fabrik'], function() {
   Fabrik.addEvent('fabrik.form.submit', function (form, e, btn) {
      if (btn.name === 'Submit For Approval') {
         form.formElements.get('yourtable___yourelement').update('1');
      }
   });
});

Then create a components/com_fabrik/views/form/tmpl/bootstrap/layouts/form/fabrik-custom-button.php (assuming you are using 'bootstrap' template)

Code:
<?php

defined('JPATH_BASE') or die;
$d = $displayData;
?>

<?php
if ($d->formModel->getId() == 29) {
    ?>
<button type="submit" class="btn btn-primary button save" name="Submit For Approval">Submit For Approval</button>
<?php
}
?>

Replace 29 with your form ID.

-- hugh
 
Thanks Hugh! I guess I should leave off the word "easy" :)

Ok...I am not able to update to latest github at the moment. Is there a way to do this on 3.5.1?
 
You'll have to copy the bootstrap template and edit default_actions to add in your custom button.

Sent from my HTC6545LVW using Tapatalk
 
Ok...I have the new button added now...but the js is not working. Let me see if I can troubleshoot some...unless you have other thoughts?
 
11am till 1pm is the middle of my night. I'm going through one of my periodic bouts of insomnia, awake till 9am.

Can you not open up a pinhole in your firewall for me to get to your site? Doing screen share sessions is a pain.

-- hugh
 
Hugh -

Have you tested this on your test environment? I am struggling getting this to work. Would there be a way to do this via PHP Form Plugin instead?
 
Yes, it works fine for me.

I guess we'll have to do a remote access session. Find me on Skype (cheesegrits, hugh dot messenger at gmail dot com).

-- hugh
 
High Hugh - I added you as a contact on Skype.

Also - I set up a whole new Joomla Test Instance...Updated 'My Site' details with the login info.

I did form_1.js and edited bootstrap template to add the custom button.

Thanks!
 
Last edited:
Hi Hugh - I am available today if you have any questions on my set up/login information to test. I am on Skype also.
 
Ok - I have figured out how to hide any of the buttons I need to, but I cannot get the if statements working.

This code will hide my referenced Submit buttons on load - working as it should:
JavaScript:
requirejs(['fab/fabrik'], function () {
    Fabrik.addEvent('fabrik.form.loaded', function (form) {
       // disable the Submit button on form load
       form._getButton('Route To Manager').style.display="none";
       //form._getButton('Route for App_Imp').style.display="none";
       //form._getButton('Submit').style.display="none";
     });
});

But when I am trying to get an elements value, it will not disable the element:
JavaScript:
requirejs(['fab/fabrik'], function () {
    Fabrik.addEvent('fabrik.form.loaded', function (form) {
       // disable the Submit button on form load
       var rtm = form_147.formElements.get('itr_2___route_to_manager_flag').getValue();
if (rtm === '1') {
       form._getButton('Route To Manager').style.display="none";
}
       //form._getButton('Route for App_Imp').style.display="none";
       //form._getButton('Submit').style.display="none";
     });
});
 
Yeah, I don't think the form elements exist when fabrik.form.loaded is fired. Although there is a fabrik.form.elements.added (or some such), probably easier to just add that as a 'load' JS event on the route_to_manager_flag element, with ...

Code:
if (this.getValue() === '1') {
   this.form._getButton('Route To Manager').style.display="none";
}

... as the code.

-- hugh
 
Follow-up question: Is there a way to only update an element's value ONLY if validation on the form does NOT fail? My problem is that this updates even when validation is failing on the form...throwing things off.
 
Not sure what you mean. If validation fails, then the form shouldn't submit at all, no data gets written to the database, and the just reloads with the validation failure warnings.

Are you saying it does write data?

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top