Last list item can't be deleted...
olio - October 27, 2007 - 20:40
| Project: | AHAH Forms Framework |
| Version: | 5.x-1.5-5 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs review |
Description
Hi,
I successfully adapted the todo-example for my own module but ran into a problem: I can add, delete and update the list of items, but as soon as I try to remove the last one, it reappears after submitting the form. I tested the original todo-example and the same thing happened.
I also tested it with the AHAH Forms Versions 1.5.4 and the actual dev version, but it seems that it has nothing to do with the version.
If this shouldn't be an issue but me overseeing something obvious, then it would be really, really nice if you could give me a hint what I should change to make it work ...
Thanks a lot!

#1
i just tried to replicate this and had problems deleting all of the todo items. steps:
* create new todo list node, add two or three items.
* save the node.
* edit the node and check the done checkbox for each of the items.
* save the node.
* notice that the items weren't deleted.
how ever if you preview the node before saving the items are deleted correctly.
#2
#3
Hi all
Do not know if this will help but we fixed it in widget example module by doing this:
In the function : function widget_expand($element, $arg2, $node) {
we change the bottom so it is:
//ADDED BY ProPeople
if ($arg2 && (!$edit[$name]['subwidgets'] || !is_array($edit[$name]['subwidgets']))){
$edit[$name]['subwidgets'] = array();
}
//END ADDED BY ProPeople
// actually build the widget and put it in the wrapper
$element[$name] += _widget_build_widget( $name, $edit[$name], $node );
return $element;
Hope this can help you guys to fix the problem.
Bests.
#4
Hi again,
I forgot to metnion that after this fix on every foreach there should be array check, or (array) casting.
Bests
#5
Hi,
@ ProPeople: First of all, thanks for your help ! Unfortunately, I didn't use the widget example module but tried to adapt the todo module to my needs. And I didn't want to spend more time for a second try. But since in the meantime ahah has made it's way into to Drupal 6 I decided that it's worth to have a second look at the ahah module problem described above. For all those who still have some Drupal 5 installations running as I do...
Finally, I found a solution:
The function _todos_extract_items() extracts the items from the form_values array, or – if the post array is empty – it loads the items from the node. The latter case is right if we enter the form for the first time (the form get populated with the stored values). But not when it's not our first visit and we have deleted ALL items. In this case, the items array has to be empty.
The attached patch inserts an additional check for the case when $edit['items'] is not an array but $edit is not empty.
Hope it helps someone,
best wishes,
Oli