Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subform "addrow" adds row with wrong id #12995

Closed
xabispacebiker opened this issue Nov 24, 2016 · 5 comments
Closed

Subform "addrow" adds row with wrong id #12995

xabispacebiker opened this issue Nov 24, 2016 · 5 comments

Comments

@xabispacebiker
Copy link

xabispacebiker commented Nov 24, 2016

Steps to reproduce the issue

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" />

Expected result

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.

Actual result

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"..

System information (as much as possible)

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.

Additional comments

@Fedik
Copy link
Member

Fedik commented Nov 24, 2016

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 😉

@xabispacebiker
Copy link
Author

xabispacebiker commented Nov 25, 2016

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, like in my case, where I'd need to get the right ID. The logical flow should be to add IDS sequentially. Actually, if you save it, rows will follow the sequence 1,2,3 .etc..

@tonypartridge
Copy link
Contributor

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.

@joomla-cms-bot
Copy link

Set to "closed" on behalf of @Quy by The JTracker Application at issues.joomla.org/joomla-cms/12995

@Quy
Copy link
Contributor

Quy commented Apr 20, 2018

See PR #19693


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/12995.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants