I am facing a problem with my cancel button in my default.php, which is a form with some input fields aswell a save and cancel button. There are some required fields in my form. When I use the cancel button, the form validation will be activated and informs me to fill out these fields.
Could it be a result of using the default.php layout?
05022015 - UPDATE
The form is a front-end form and the cancel button has been done via Joomla custom JToolBar
06022015 - Add reduced code of layout
<?php
defined('_JEXEC') or die;
JHtml::_('behavior.formvalidation');
JHtml::_('behavior.keepalive');
JHtml::_('formbehavior.chosen', 'select');
?>
<script type="text/javascript">
Joomla.submitbutton = function(task)
{
if (task == 'contact.cancel' || document.formvalidator.isValid(document.getElementById('contact-form')))
{
alert (task);
Joomla.submitform(task, document.getElementById('contact-form'));
} else {
if (task != 'contact.cancel' && document.formvalidator.isValid(document.id('contact-form'))) {
Joomla.submitform(task, document.getElementById('contact-form'));
} else {
alert('<?php echo $this->escape(JText::_('JGLOBAL_VALIDATION_FORM_FAILED')); ?>');
}
}
}
</script>
<form action="<?php echo JRoute::_('index.php?option=com_ecms&view=contact&id=' . (int) $this->form->getInput('id')); ?>" method="post" name="contactForm" id="contact-form" class="form-validate" enctype="multipart/form-data">
<div class="row-fluid">
<fieldset class="form-horizontal">
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('id'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('id'); ?>
</div>
</div>
<div class="control-group">
<div class="control-label">
<?php echo $this->form->getLabel('surname'); ?>
</div>
<div class="controls">
<?php echo $this->form->getInput('surname'); ?>
</div>
</div>
</fieldset>
<div id="toolbar-cancel" class="btn-wrapper">
<button class="btn btn-small" onclick="Joomla.submitbutton('contact.cancel')">
<span class="icon-cancel"></span><?php echo JText::_('JCANCEL') ?>
</button>
</div>
</div>
<?php echo JHtml::_('form.token'); ?>
</form>