"Add another item" button fails to add new item for a flexifield inside a group
effulgentsia - August 12, 2009 - 22:56
| Project: | Flexifield |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | needs review |
Description
This is a carryover of http://drupal.org/node/399886#comment-1809212.

#1
Changed title.
#2
Subscribing. I have the same issue and am willing to test patches.
#3
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_linksWith a fieldset the url is:
http://localhost/flexifield/ahah/addmore/profile-charity/field_networking_links/group_networking_links%3Afield_networking_links/field_networking_linksNotice 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.
#4
Any updates on this bug? it has been a while.
#5
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()
<?php$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
<?php$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
<?php// 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):
<?phpif (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
#6
This is critical.
#7
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!
#8
subscribe
#9
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)
#10
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...
#11
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.
#12
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
#13
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.
#14
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.
#15
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.
#16
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
#17
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