• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Create an auto increment numeric field

madpato

Member
Hello

I need to create something pretty much like an id with auto-increment but then i encounter small issues like if i have a repeat. group if i create a new entry it shows me the next number despite its another record (since its using the ID field, i was expecting something like this).

So if i noticed this is not a viable option, how can i do this? See this link for details: http://desarrollo.tilatam.com/tns4/index.php/reuniones

Thanks
 
How are you currently creating it? What is the element name/id? I don't see anything which looks like what you are describing in the element list on the backend.

Are you trying to do this on the main table, or one of the joined / repeated tables?

-- hugh
 
The name of the field is: tns_reuniones_capac___id this is for the repeated tables. ID of the item 344 Thanks.
 
OK, I really don't understand what you are trying to do.

Can you give a fuller explanation of what you are trying to achieve?

-- hugh
 
Ok this is rather simple, all i need is a field (any type) with a number that autoincrements whenever i create a new entry in the rep. group, this has to be in order starting always from number 1 and so on whenever i press the "+" to add a new entry on the group. Is just that i dont see how simpler can i put it. Guess i have to contact you on Chat so i can answer bettter your questions. Regards.
 
OK ... which is exactly what the 'id' we automatically create on repeated groups is. An auto-incremented integer value.

However, that 'id' is only available AFTER the rows are saved, on form submission, as it's generated my MySQL during the row insert.

Which is why I need to know more about what you want to use it for. If you need it displayed when you press the "+" button, then it's a lot more complicated than you might think. For instance, do you have more than one person using this form?

If so, consider the issue of two people, both with the form loaded, both pressing the + buttons in their form. Your number needs to be unique, but if it is being calculated in JavaScript in the browser when the + button is pressed, how can it take account of someone else doing the same thing?

The only way to achieve this with any hope of having a unique number is to maintain a separate table, like "my_repeat_ids" (with one row per table you want to do this for, which stores the list ID and the last number used), and have a user_ajax.php method which gets called via AJAX when the + button is pressed, runs PHP on the server to look up the next number to use in that table, updates that table to increment that numberm and return the value to your custom JS, which inserts that value in to the field on the form.

Of course, this means you'll have gaps in the number sequence, for instance if someone doesn't submit the form after adding new repeat groups.

So ... as I said, give me more info about exactly what you are trying to achieve, so we can nail down just how far we need to go to achieve it.

-- hugh
 
OK, as per our live chat conversation, I now understand what you need, which is an incrementing serial number starting at 1 within each repeat group, rather than for the entire table.

So ... first thing, don't touch that 'tns_reuniones_capac___id' element, if it's the one that got created by Fabrik when you created the repeat group. That's "for internal use only", and you repeat group won't work if you mess with it.

Create a new field element, called something like 'serial_num'.

Add a form PHP plugin, running onBeforeProcess, which does this:

PHP:
foreach ($formModel->formData['tns_reuniones_capac___serial_num'] as $key => $serial_num) {
  $formModel->formData['tns_reuniones_capac___serial_num'][$key] = $key + 1;
  $formModel->formData['tns_reuniones_capac___serial_num_raw'][$key] = $key + 1;
}

-- hugh
 
This worked like a charm except for one small detail, what if i need to apply the same thing but for another element on the same form? how do i add another element?

Thanks!!
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top