My use case:

Step 1: I have a tablefield defined with 2 columns and 9 rows where the top row is the header and the first column has defined default values, therefore presenting the end user with the ability to enter values for those pre-defined options:

Default values table

(ignore the third column in the above image, as it shouldn't be there for the purposes of this example)

Step 2: As a regular user: I edit this field (wherever it may be- user/node etc.) and save my entries in the second column. So far so good.

Step 3: As an admin: I then go to edit the field settings (for the tablefield created in Step 1) to add another default value in the first column (by rebuilding the table with an additional row and entering the default value in column 1, row 10) and save the form.

Step 4: As a regular user: I return to edit the field and I can't see the newly created default value in column 1, row 10, because the widget form is 'rationalized' from the saved data. From this unserialized/rationalised data, the number of rows and columns are calculated for rebuilding the form.

This is not always the intended behaviour, especially when the rebuild table options are set to be excluded for the end user.

Therefore, my workaround is to provide a instance level option to allow site builders to say whether the values for cols/rows defined in the default value should always be respected. On the field settings form it looks like this:

New instance option

When the widget form gets built, and this option is set, then the rows/cols values (part of the default values rebuild options in the field settings form) get used as the basis for the size of the tablefield to build.

This works for my use case, but will likely still need to be tested in the cases of ajax, field collection and the other more advanced use cases this module should support. I'm putting this out there for feedback and review. Marking as feature request, as this may not technically be a bug in what the intended functionality has been to date. That said, it causes issues with my use case, which may not be all that common. It would be good to know if anyone else has come across this quirk of the module to date. I couldn't find any directly related issues in the queue.

Patch to follow.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Barry_Fisher’s picture

Patch as per Original Post

Barry_Fisher’s picture

Issue summary: View changes
lolandese’s picture

Version: 7.x-2.4 » 7.x-2.x-dev
Status: Active » Needs work

The patch probably could use a reroll against the latest dev.

lolandese’s picture

Version: 7.x-2.x-dev » 7.x-3.x-dev
lolandese’s picture

Reroll removing the extra added option as it seems to be better covered by a combination of existing settings. The idea of using the widget settings however led to a new feature request: #2863947: Move options from TABLE FIELD SETTINGS to widget instance SETTINGS.

The rebuild restrict option now acts as follows. Avoids the number of cols/rows being changed by content editors. For all users if in combination with locked cells. Only for users without the permission "rebuild tablefield" in other cases. This way also the superuser (uid=1) will see the content tables changed with new default values. This removes the ability also for this user to add/delete rows/cols for an individual table. They can still do it on the field settings (default). This is most likely the intention of a table with both restricted rebuild permissions and locked header. It's better to have the same behavior for all users in that case.

The patch still solves the original issue making added default values visible when editing existing content. It furthermore adds option descriptions.

lolandese’s picture

Status: Needs review » Fixed
lolandese’s picture

Status: Fixed » Needs work

Does also act on tables that don't have locked cells. Might be due to changes made in other issues as it was tested. To check.

lolandese’s picture

  • lolandese committed b69c50a on 7.x-3.x
    Issue #2514096 by lolandese, reallifedigital: Adapt to other commits.
    
lolandese’s picture

Status: Needs work » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.