I need a blank calc field when adding a new repeat group

ricslabb03

Member
I am having an issue with my repeat group. I need a blank calc field then I add a new repeat record, but it duplicates the first saved calc field's value. Is there any way that I can prevent it from doing this and rather keep the value initially blank? Should I use the fabrik.form.group.duplicate.end function? Can someone please give me an example of how to use this function in this situation (just as a template that I can work off)

Thanks
Richard
 
This is what I have for my form_70.js:
JavaScript:
requirejs(['fab/fabrik'], function () {

    Fabrik.addEvent('fabrik.form.group.duplicate.end', function (form, event) {
       
   
          var groupId = 88;

          // Get the number of times the group has been repeated
          var repeatMax = form.repeatGroupMarkers[groupId];

          // Get the newly added element
          var el = form.formElements['join___150___quote_items___area_items_' + repeatMax];

          // Update the element with an empty string
          el.update('');
    });

});

But it gives this error:

TypeError: el is undefined

el.update('');

I got this code from http://fabrikar.com/forums/index.php?wiki/form-javascript-objects/
 
Did you try debugging it, using something lie Chrome's dev tools?

That code is out of date. We no longer use the join___XXX___ prefix for repeated elements. So it's just quote_items___area_items_.

It's worth taking a few minutes to learn the basics of JS debugging. Very simple. You can just put a breakpoint in your code, then look at what all the variables are set to.

http://screencast.com/t/5OdBtKBhD40

-- hugh
 
I also notice that adding a new group, elements do not adhere to the default option that is set for that element.

It seems to copy the first group details.

Is there a reason for this? Is there a way to switch this off?

Paul
 
Something interesting happened. I implemented your changes, Hugh, and started playing around with Dev Tools. I found out that the other elements in the repeat group are creating CloneObjects, but this calc is not and so when I try to reference it with the repeatMax it gives an undefined error since it does not exist. Is there any way that I can fix that so that the calc creates a CloneObject for me? How did it work on your side?

Richard
 
Are you seeing any other JS errors?

The calc should have a cloned object, certainly does on my tests.

If you want to point me at the page I can take a quick look, see if it's anything obvious, but I can't do much by way of in depth investigation in Community support.

-- hugh
 
Thanks Hugh,

We decided to take a different approach.

We made the repeat group add/delete functionality readOnly and placed a button in the groups intro using this code:

Code:
{source}

<script language="javascript" type="text/javascript">

function ProductGroup() {
 
        var getUrl = window.location;      
        var baseUrl = getUrl.protocol + "//" + getUrl.host + "/" + getUrl.pathname.split('/')[1];

        var qid = $('quotes___id').value;
        console.log(qid);
        Fabrik.getWindow({id:'uniqueid',
                          'loadMethod': 'iframe',
                          'contentURL': baseUrl +'/index.php/product-group?qid=' + qid+ '&tmpl=component',
                          'title': 'Add/Edit Product Group',
                          'width' : 800,
                          'height' : 600 });
}

</script>

<?php
     
echo '<button id="product" type="button" class="btn btn-info" onclick="ProductGroup();">Add/Edit/Del Product Group</button>';

?>
{/source}

Here we open up a Fabrik popup window and display the associated list of the repeated group items.

You then add as many items in the list as necessary. We created a button that essentially applies the parent form. This will ensure that the new repeat group items are shown. Here is the code:

Code:
{source}
<?php

$mainframe = JFactory::getApplication();
$qid =  $mainframe->getUserStateFromRequest( 'qid', 'qid', 0 );
echo '<div style="width: 90%; margin: 0 auto;">';
echo '<br />{fabrik view=list id=88 quote_items___quote_id='. $qid .'}';
echo '<button type="button" class="btn btn-info" onclick="parent.Fabrik.getBlock('form_70').mockApply();">Save and return to Quote</button>';
echo '</div>';

?>
{/source}

(Our custom mockApply() function essentially does the same as the mockSubmit() function, but doesn't redirect to the list once the form is saved.)

Richard
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top