Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

Title: "Add more button" fails to add new item for a flexifield inside a group » "Add another item" button fails to add new item for a flexifield inside a group

Changed title.

Nigel Cunningham’s picture

Subscribing. I have the same issue and am willing to test patches.

nicholas.alipaz’s picture

From what I can tell the POST url seems to be incorrect:

Without a fieldset the url looks like:

http://localhost/flexifield/ahah/addmore/profile-charity/field_networking_links/field_networking_links/field_networking_links

With a fieldset the url is:

http://localhost/flexifield/ahah/addmore/profile-charity/field_networking_links/group_networking_links%3Afield_networking_links/field_networking_links

Notice the %3A, that looks to be the issue, but I could certainly be wrong. Let me know if there is anyway I can help. I was able to find a bunch of info under firebug's "XHR -> Net" tab.

nicholas.alipaz’s picture

Any updates on this bug? it has been a while.

abaddon’s picture

Status: Active » Needs review

im setting this as needs review to get some advice from the maintainers on the below

the above %3A is not a typo
the url gets set in file flexifield/flexifield-widget.inc , line 92 , function _flexifield_alter_multiple_values_form_process()

  $sAhahPath = implode('/', array('flexifield-filefield', 'ahah', $aElement['#type_name'], $aElement['#field_name'], $aElement['#delta'], implode(':', array_slice($aElement['#array_parents'], 0, -2))));

the processing flow goes to flexifield_ahah_addmore() , line 243
there the argument above is expanded to an array again, and the field itself is removed, leaving only its parents, if any, in the array

  $aParents = explode(':', $sParents);
  while (array_pop($aParents) != $sFieldName) {}

the next part im blurry about, if there arent any "parents" the code works as expected, but the processing flow goes to another function as seen below
if there are parents (like a fieldgroup), the processing flow continues below this code, and it fails to "add another item" to an unlimited items field, it just refreshes the field

  // If this is the root flexifield, then use content.module's way of
  // adding another item (with a small modification).
  if (!count($aParents)) {
    module_load_include('inc', 'flexifield', 'flexifield-cck-overrides');
    return flexifield_add_more_js($sTypeNameUrl, $sFieldName);
  }

to fix it, im sabotaging the "if" above, making it run regardless, something like this (or remove it altogether):

  if (1 || !count($aParents)) {
  .......

im pretty sure im breaking something with this, but its probably not something that im using(?!)

to all : please let me know if this works as expected for you as well?
to maintainer : do you know what is the logic of the code below this "if" and any advice to fix this better?
,thanks

crea’s picture

Priority: Normal » Critical

This is critical.

effulgentsia’s picture

Version: 6.x-1.0-alpha5 » 6.x-1.x-dev

Apologies for being remiss in maintaining my issue queue. See project page for more info about that. However, I did make a commit to dev which I think fixes this, but don't have time today to test it properly. Can one of you please test it for me? Thanks!

bmddddd’s picture

subscribe

keva’s picture

Having the same problem with a flexifield within a flexifield.
Flexifield 6.x-1.x-dev results in the same errors as flexifield-6.x-1.0-alpha5.

Tested 6.x-1.x-dev using dru6.14 and both CCK2.4 and CCK3.x-dev

basic setup:
Parent node
- flexifield 1
   - text fields
   - flexifield 2
      - text fields

Adding another flexifield 1 works fine
Adding another flexifield 2 produces these errors:

cck 6.x-2.4 on localhost:

The page at http://localhost says:An HTTP error 500 occurred.
/classtest2/flexifield/ahah/addmore/addmore/class/field_classlisting%3A0%3Avalue%3Afield_classtimes/field_classlisting%3A0%3Avalue%3Afield_classtimes

cck 3.x-dev on dev server:

The page at http://... says:An error occurred.
/~classtest3/flexifield/ahah/addmore/addmore/class/field_classlisting%3A0%3Avalue%3Afield_classtimes/field_classlisting%3A0%3Avalue%3Afield_classtimes
Fatal error: Maximum execution time of 30 seconds exceeded in /home/classtest3/public_html/sites/all/modules/flexifield/flexifield-widget.inc on line 244

Warning: MySQL server has gone away (etc)

bmddddd’s picture

I got something!

There are wrong parameters passed to the function.
function flexifield_ahah_addmore($sTypeNameUrl, $sFieldName, $sParents, $sDataParents)
Inside a group, $sTypeNameUrl is "addMore" but it should be the content type which holds the fields.
Also $sFieldName is wrong, it holds the actual content type which should be in $sTypeNameUrl, but should be the name of the field you whant to add.

Since I just use it in one place I did a conditional stetement testing the "addMore"-Value and fixing it to the right values ... tada! worked for me... but is quiet dirty since I don't know where the parameters originally come from...

penguin25’s picture

Since nobody has repsonded to post #5, I thought I'd say that the suggestion in that post has fixed this problem for me. Presumably the area that the suggested workaround breaks would be nested flexifields inside other flexifields? I don't have any of those in my site to test, unfortunately.

abaddon’s picture

you guys should check and answer to comment #7 from the module maintainer, do this versus my comment at #5 - i cant spare the time for this right now, and i didnt use the -dev release

effulgentsia’s picture

Hi all, in case anyone here hasn't read my status update on the project page, I wanted to say that I apologize for not having maintained this module well for the past couple months. I've been busy helping out on Drupal 7 core development. The code freeze for that was originally scheduled for 10/15, then extended to 10/19, we hit a snag on a couple important issues, and are now waiting for Dries to announce what is to happen to them. I'm pleased with what everyone has been able to accomplish with Drupal 7 prior to the freeze, and with my small contributions to it. I will be resuming maintenance on flexifield within the next couple days. Thank you for your patience.

Nigel Cunningham’s picture

Sorry for not replying - I haven't been watching the status of my issues. I'll try it out as soon as I can find some time.

mpaler’s picture

Work around in #5 doesn't work for me. Only allows one additional row to be added.

My flexifield is simply two textfields.

This flexifield is wrapped in a field group in a parent form.

mpaler’s picture

The fix in #5 is partially right.

The check around line 252 in flexifield-widget.inc should be removed:

if (!count($aParents))

However, the problem I was having is that I was moving my flexifield into a system defined cck fieldgroup (in this case ubercarts product fieldgroup) using hook_form_alter and my widget was still failing.

The problem was in flexifield-cck-overrides.inc around line 215:

  // Add the new element at the right place in the (original, unbuilt) form.
  if (module_exists('fieldgroup') && ($group_name = _fieldgroup_field_get_group($type['type'], $field_name))) {
    $form[$group_name][$field_name] = $form_element[$field_name];
  }

Which looks to see if your flexifield is wrapped with a field group in the parent cck settings. In my case this fails.

I think a more extendable solution is to pass the fieldgroup name at runtime to

flexifield_add_more_js($sTypeNameUrl, $sFieldName);

My patches are attached (I forget how to do multi-file patches). The files need further cleaning up because with these patches there will be some useless code in there....but I'd like to get some feedback before I do any more...

This code is tested with a flexifield wrapped in a field group in it's own cck definition, as well as when the flexifield is in fieldgroup in another cck type.

Mike

ssm2017 Binder’s picture

using the patch in #15 :
i can add a new item but only one item
if pushing again the button to add another new item, the progress is turning, then, nothing appears
i need to save the node to add a new item again

benone’s picture

subscribe

mrlava’s picture

same problem =/

HnLn’s picture

subscribe

yogesh1110’s picture

Hi Mike
Thanks for sharing your code here. It's works for me perfectly.

DavideOrazio’s picture

Subscribe.

isopharius’s picture

patch #16 works for me thanks

Nigel Cunningham’s picture

Status: Needs review » Reviewed & tested by the community

Patches in comment 16 work for me too.

blecheimer’s picture

#16 worked for me too. Thanks!

friedenz’s picture

Hello. For me the patch in #16 solve that problem but now. Mi fieldgroup collapse over and over after I add another item. Someone could help me.

effulgentsia’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for all the testing, everyone! I committed an alternate solution than #16, but #16 was very helpful in figuring out the problem. The committed solution solves #26 too.

friedenz’s picture

Hello effulgentsia. It still doesn't work for me. Could you help me. Please see http://www.estoydesempleado.com/node/add/curriculum and then in "Experiencia Laboral".

Tank's

stefan81’s picture

hi, are this fixes applied to 6.x-1.x-dev?

barckhoff’s picture

subscribe

willhowlett’s picture

Subscribing

Status: Fixed » Closed (fixed)

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

rikvanderkemp’s picture

Status: Closed (fixed) » Active

Re-opening this bug report. This is still an issue. Patches provided above do not solve this problem. Anyone fixed this already?

samccone’s picture

I am having the same issue, the patch at 16 does not solve my problem,

the only time the issue occurs is when adding a new flexifield within a flexifield

this is the error message i get
An error occurred.
/flexifield/ahah/addmore/addmore/........

Isostar’s picture

I used the dev version, but see the same problem.

In the firebug console I see:
{ "status": true, "data": "\x3cdiv class=\"messages error\"\x3e\n \x3cul\x3e\n \x3cli\x3ewarning: Parameter 2 to date_form_alter() expected to be a reference, value given in /var/www/iff2/includes/common.inc on line 2883.\x3c/li\x3e\n \x3cli\x3ewarning: Parameter 2 to date_timezone_form_alter() expected to be a reference, value given in /var/www/iff2/includes/common.inc on line 2883.\x3c/li\x3e\n \x3cli\x3ewarning: Parameter 2 to domain_form_alter() expected to be a reference, value given in /var/www/iff2/includes/common.inc on line 2883.\x3c/li\x3e\n \x3cli\x3ewarning: Parameter 2 to peek_form_alter() expected to be a reference, value given in /var/www/iff2/includes/common.inc on line 2883.\x3c/li\x3e\n \x3cli\x3ewarning: Parameter 2 to wysiwyg_form_alter() expected to be a reference, value given in /var/www/iff2/includes/common.inc on line 2883.
...

It seems to be an incompatibility with php 5.3

I don't get those errors when I do 'add another item' with a 'normal' field

willhowlett’s picture

I applied the patch at #16 to the alpha-5 version of the module and it seems to have fixed the problem, whereas the latest dev version gives me an error message ('An error occurred.
/flexifield/ahah/addmore...') when clicking 'Add another item'.

jjemmett’s picture

Isostar, I am getting the same error as you, however this seems to be a separate case. And should be moved into it's own issue.

edit: Isostar, also make sure you don't have the theme developer module installed as it breaks flexifield.

ankitchauhan’s picture

hi

I have applied both patch. It's working fine, but still have some problem with validate. my flexifield is required and i am using conditional field module.

zarexogre’s picture

For flexifields within flexifields I have a patch which works. Its just tweaks the urls to be correct.

r3z0nate’s picture

Thank you! You saved me some time trying to fix the same issue. It did work as it was expected, and I was hoping it was the last hurdle but unfortunately I'm having a problem with another item.

I'm trying to create a form with a row of fields that can be added an unlimited number of items, with each row including a sub-row that can be added an unlimited number of times. Since the the sub-row has to be nested, the only way that I found it could be done was by creating 3 node types. I have the layout exactly how I need. There are no issues adding rows to either node type.
For some reason, it will not save a new node. If I create a new node from the 2nd or 3rd node type, the node is saved correctly.

Is it as simple as switching where the multigroup is? Is this even possible, or have I made it over complicated? I tried other methods, but either didn't have the rows nested or had the fields being saved incorrectly in the database.

Node 1
-Flexifield of Node2 (unlimited rows)
Node2
-Fields (limited to 1)
-Flexifield of Node 3 (unlimited rows)
Node 3
-Multigroup
--Fields (limited to 1)

Dret’s picture

FileSize
28.57 KB

Same Issue for me,

I have a multivalue Flexifield nested inside another multivalue Flexifield... but the Add Button for the Inner one... is not working.

Thanks, bye!

SGhosh’s picture

#40 - zarrex

The patch's great. It solved the issue of multiple fields showing up by default.

I have a content type - which has a flexifield - this flexifield has a flexifield within it. The inner most flexifield has a date field.

Both flexifields are multiple valued.

The "Add another item" for the innermost flexifield(Task) was working but adding a maximum of 2 fields, trying to add more fields had no effect; commenting out

$item_count = count($items);
  $form_state['item_count'][$field['field_name']] = (isset($form_state['item_count'][$field['field_name']]))
  ? $item_count + 1
  : (($item_count) ? $item_count - 1 : 0);

solved the issue.

Using the "Add another item" for the outer flexifield(Milestone) adds an extra Task to the previous Milestone if this previous Milestone has only a single Task.

I also have a date field in Task. When adding a new Milestone or Task the date fields values are all being removed and replaced by 2.

Cannout find the issue!! Please help.