Override Joomla.submitbutton = function(task) or add some task before

610 views
Skip to first unread message

ced1870

unread,
Dec 16, 2015, 3:16:15 AM12/16/15
to Joomla! General Development
Hi all
During my developments I have to add some interaction with the user by adding some JS elements in the page. Before saving (in a module for example) I have to clean the page and remove these elements.

I need to do some Javascript before the page is saved. The only method that I have found for now is to override the "submitbutton" function. But this is not a correct method as this function can be different in admin and front.

Is there a method to catch the submitbutton call and do some JS work before it calls the submitform function ?

Thank you
CEd

PGS

unread,
Dec 16, 2015, 4:30:20 AM12/16/15
to Joomla! General Development
In a classic joomla submit button, just add the function you want:
<button type="submit" class="validate btn btn-primary" onclick="myfunction()"><?php echo JText::_('JSUBMIT'); ?></button>

It will execute the function "myfunction()" and then the "Joomla.submitform()".
At least, that's how it worked fr me, try it.
Let as know the result.

ced1870

unread,
Dec 16, 2015, 5:00:33 AM12/16/15
to Joomla! General Development
Thank you but this is not what I need here
The button is already generated.
Imagine that you want to add a code before the save method in a module edition, the save button is automatically rendered by the system.

I'm trying something like this that seems to work :
var Myvar = {};
Myvar.submitbutton = Joomla.submitbutton;
Joomla.submitbutton = function(task) {
... custom code here ...
Myvar.submitbutton(task);
}

If someone else have an idea :)
Reply all
Reply to author
Forward
0 new messages