Create a basic subform
<field name="lines" type="subform" formsource="/administrator/components/com_dummy/models/forms/line.xml" min="1" max="30" multiple="true" buttons="add,move,remove" layout="joomla.form.field.subform.repeatable-row" groupByFieldset="false" />
When adding a row the new data-group id should be equal to the lenght of the subform rows to follow the last index id+1.
The first added row data-group id will be equal to the last index +2. For example, if we have one row, the data-group id would be 0, then we add a new row and the data-group id of the recently created row will be 2.
<tr class="subform-repeatable-group" data-base-name="lines" data-group="lines0"..
<tr class="subform-repeatable-group" data-base-name="lines" data-group="lines2"..
Its a problem with the javascript subform-repeatable.js, on line 151 countnew is set to either lastRowNum+1 or count+1 which is always the rows length + 1. It should be rows.length to follow the logical sequence.
| Labels | 
                                        Added: 
?
 | 
    ||
indeed, it is a bug. It does not add random numbers but the rows length. Programming must follow some logic or it may become a mess for developers. It's just a matter of simplifying/minifying code, as in my case where I'd need to get the right ID without having to do a lot of checks in my code. The logical flow should be to add IDS sequentially. Actually, if you save it, rows will follow the sequence 1,2,3 .etc..
Agreed this is a bug, I recently had it with a custom form with subfields, but just wrote around it with my check doing an each opposed to looping through the max limit of possible sub forms as if you do a check for form0, form1, form2 then form1 would return nan and you would assume form2 no longer exists.
We should +1 based off current loading sub form.
| Category | ⇒ | Fields | 
| Priority | Medium | ⇒ | Low | 
| Status | New | ⇒ | Confirmed | 
| Status | Confirmed | ⇒ | Discussion | 
| Status | Discussion | ⇒ | Closed | 
| Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-04-20 20:13:32 | 
| Closed_By | ⇒ | Quy | 
| Status | Closed | ⇒ | Discussion | 
| Status | Discussion | ⇒ | Closed | 
| Closed_Date | 2018-04-20 20:13:32 | ⇒ | 2018-04-20 20:13:33 | 
| Closed_By | Quy | ⇒ | joomla-cms-bot | 
Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/12995
See PR #19693
it not a bug, it feature?  
but why do you think ID is wrong??  ?  ?  
there each ID are unique, there no duplication, so all fine. If it does not go 1.2.3...X does not meant it is wrong
Even more, if you start add/remove/move rows, then the numbers order will become even more random