How to INITIALLY show repeat group ?

mr_snappyz

Member
Hi ,

I have a question,

How to initially show repeat group without pressing add (+) button ?

for example,

Form Assesment Mark

Course Code : EKC123
Student ID : abc1234

//Repeat group
Assesment : Quiz1 Mark : _____
Assesment : Quiz2 Mark : _____
Assesment : Quiz3 Mark : _____



Assesment is repeated group (database join) ... each course code may have different number of assesment ...


Thanks.
 
Thanks Rob .... Setting the minimum repeat group value will initially show the repeat group ...

Sorry, I may not have explained my question well ... actually I want to repeat group base on the number of Assesment the Course Code have ...

let say, Course Code EKC123 have 3 Assesment named Quiz1, Quiz2 and Quiz3 .. i want to set the MINIMUM repeat group value to 3 and autofill the Assesment (database join element) with Quiz1 , Quiz2 ,Quiz3 .... so, user only need to fill in the Mark element ...


Example:

Course Code : EKC123
Student ID : abc1234

//Repeat group
Assesment : Quiz1 Mark : _____
Assesment : Quiz2 Mark : _____
Assesment : Quiz3 Mark : _____
 
Somebody please help me ...

Just want to know how to set minimum repeat group automatically and set default value for database join element for each repeated groups ...

Thanks
 
It's not a simple thing to do. We don't have a built in way of doing it, as the 'minimum repeats is a static value. You'd probably have to do this in JavaScript on the page, which wouldn't be trivial if you aren't well versed in JS.

-- hugh
 
I think I still need a hand in javascript to show or render repeat group base on the number of data in database... It is same like we use "minimum repeat value" in group setting...

Sent from my MB865 using Tapatalk 2
 
As I said, this is a non trivial to do. I know, 'cos I tried doing it a while back as a custom JS script, and gave up.

If you look in our form.js, you'll find a method called duplicateGroupsToMin(), which shows you how we add empty groups to the min setting.

You should be able to do something very similar use an X.js form script.

But this really isn't something I can help with in Community support.

-- hugh
 
The main thing you'll need to add to that code I pointed at is probably an AJAX call to the server, to find out how many groups you need to add, using a user_ajax.php file, with a function that looks up the assessment count for that course code.

-- ugh
 
OK, it occured to me that I could probably make your job a lot easier if I added a Fabrik event at the start of the duplicateGroupsToMin method, which allows you to override the min setting. I'm testing it at the moment.

So sit tight, and hopefully I'll have a much easier way for you to do this in a few minutes. You'll still need an AJAX call to the server to grab the repeat count, but it'll save you all the hassle of overriding our standard code that sets up those repeats.

-- hugh
 
OK, I've pushed that change up to github. So, update to latest github, then create a ./js/form_X.js file (where X is your numeric form ID), in which you can now do something like this:

Code:
Fabrik.addEvent('fabrik.form.group.duplicate.min', function (form) {
    // insert code here to get repeat count from the server
    // with an AJAX call, and set this var.  For this example
    // just setting it to 3 as a test.
    var rcount = 3;
 
    // You'll need to know your numeric group ID as well,
    // so you can override the repeat min setting in the form object
    form.options.minRepeat[123] = rcount;
})

So, you can test this by just changing that [123] to your actual group ID, which is the ID on the left column of your main groups list on the backend.

If this works, which it does for me, then the next step would be to create a user_ajax.php, and build the JS / PHP to grab the count. The way to get started on that is to copy ./user_ajax_example.php, at the root of the main ./components/com_fabrik folder, to user_ajax.php, and read the comments in that.

-- hugh
 
The following is not any today's feature, but even if nonimplementable then still something that could help to have ideas :)

Today we can use daisy chain joins in form but every joined group is displayed separately.
I think maybe this "repeat group ready for filling in" could be possible if such feature as nested joined groups would be implemented. So that e.g under each repeating group could be another nonrepeated. Not sure - perhaps something additional would be needed, as using RIGHT JOIN (option exists in list admin but it is not usable or I just don't know how it works).

In this case one of our joined group would contain the "labels" joned to the course EKC123 and the other one (joined to the "labels") fields to be filled by student abc1234.

Joined1 / Joined2
ID course Assesment / Mark AssesmentID studentID ID
1 EKC123 | Quiz1 | | 1 abc1234 (new)
2 EKC123 | Quiz2 | |2 abc1234 (new)
3 EKC123 | Quiz3 | |3 abc1234 (new)

The data would be something like this when used display mode "table". Joined1 is repeated and Joined2 created as non-repeated but the fields are repeating because joined to the repeated data.

P.S Oh no. I hoped that here is possible to present your ideas as tables. I copied from excel to here but all possible table tags seems to be stripped. Had to write /, || etc. Very bad :(
 
Thank you so much Hugh.. Thanks for your efforts and time.. It is really appreciated.

I need some time to figure it out because of my limited knowledge of javascript/ajax :)

Beside using javascript i tried to use php plugin to pre insert the repeat data using sql insert into but still no success.. haha

Ok now i'll try the solution you give..

Thanks again

Sent from my MB865 using Tapatalk 2
 
Beside using javascript i tried to use php plugin to pre insert the repeat data using sql insert into but still no success.. haha

I have done this before, but it's not simple, especially if creating a new form, because obviously the main row doesn't exist yet, which makes it tough to create joined rows with an FK pointing to the PK of the main row ... because it doesn't exist. So what you have to do is use the onBeforeLoad hook, create the main form row, create the joined rows pointing to it, then modify the request params, set a rowid=X, and set the internal rowid on the form model. It took me a while to get that going, and I suspect it'd be easier for you to go the AJAX route.

AJAX isn't actually that hard. The comments in the user_ajax_example will tell you most of what you need to know. How to send the data your server side PHP will need (in this case the course code), and how to process that on the server side.

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

Thank you.

Members online

Back
Top