Clash between element js and custom submit button in repeat group

ricslabb03

Member
Hi,

I have a calc field in a repeated group (quote_items) that returns an html submit button:

PHP:
$button = '<button class="btn btn-success button save" name="edit_items" type="submit" value="clicked">Edit Area Items</button>';
return $button;

(I didn't use a button plugin, because I need to pass the value "clicked" to the button.)

In this element I fire some element js:

JavaScript:
var rnum = this.getRepeatNum();

var rc = Fabrik.getBlock('form_70').formElements.get('quotes___repeat_counter');
console.log(rnum);
rc.update(rnum);

This updates a field in the parent table quotes. I need to update quotes___repeat_counter for the following form onAfterProcess php plugin to work:

PHP:
$rnum = $formModel->getElementData('quotes___repeat_counter');
$qid = $formModel->getElementData('quotes___id');

$qiID = $formModel->getElementData('quote_items___id', false, '0', $rnum);

// make sure main submit buttons aren't affected
$app =& JFactory::getApplication();

$clicked = isset($_POST['edit_items']) ? $_POST['edit_items']  : '' ;

if( $clicked == 'clicked' ) {
    $app->redirect(JRoute::_(JURI::root().'index.php/area-items?qiid='.$qiID.'&qid='.$qid.'&tmpl=component', false));
}

(You see why I needed to pass the "clicked" value into the button.) I basically used the quotes___repeat_counter value to get the id of the repeat group which I then needed to use to redirect to another location ie 'index.php/area-items?qiid='.$qiID.'&qid='.$qid.'&tmpl=component'.

The problem I'm having is that it seems as though it can either run the submit button html code or the element javascript, not both similtaneously. What's happening is that if I press the button for a saved repeat row it fires the submit, but not the element javascript and so redirects the page to the wrong list. However, when I create a new row in the form and press the button, the element javascript runs, but not the submit button's html script. (Btw, the element javascript works for an ordinary button what doesn't redirect.)

Thanks for your help :)

See screenshot below for my basic form layout.
 

Attachments

  • area items.png
    area items.png
    84 KB · Views: 82
I found these two threads by the same person:
http://fabrikar.com/forums/index.php?threads/button-element-submit-on-joined-form.43081/
http://fabrikar.com/forums/index.php?threads/ajax-button.43067/

Cheesegrits suggested using mockSubmit()

Here are my files now:
user_ajax.php
PHP:
class UserAjax {
   public function doButton() {
      $result = "foo bar";
      echo $result;
   }
}

form_70.js
JavaScript:
function doButton(el) {
    var url = "index.php?option=com_fabrik&format=raw&task=plugin.userAjax&method=doButton";
    new Request({url:url,
        onComplete: function(response) {
            if (response != '') {
                el.form.mockSubmit();
            }
        }
    }).send();
}

and in the element js:

JavaScript:
var rnum = this.getRepeatNum();

var rc = Fabrik.getBlock('form_70').formElements.get('quotes___repeat_counter');
console.log(rnum);
rc.update(rnum);

doButton(this);

The console is returning el.form.mockSubmit(); as undefined. Am I calling it incorrectly? and el.form --> is form a variable I have to define? Basically this doButton is not saving the form.
 
Back
Top