Home » HTML » HTML_AJAX » Bug #9399
Additional DOM manipulation Actions
Details
| Request #9399 | Additional DOM manipulation Actions |
|---|---|
| Submitted | 2006-11-20 23:44 UTC |
| From | jazzslider at gmail dot com |
| Status | Bogus |
| Package | HTML_AJAX |
| PHP Version | 5.1.4 |
| OS | Linux |
| Roadmaps | (Not assigned) |
Comments
[2006-11-20 23:44 UTC] jazzslider at gmail dot com
Description:
------------
It would be very helpful to me if HTML_AJAX_Action were extended to include more of the standard DOM API.
For instance, there does not currently seem to be an HTML_AJAX_Action method that correlates to "appendChild()"; it would be extremely useful to be able to add child elements rather than sibling elements only (as in the current HTML_AJAX_Action implementation).
I realize this can often be accomplished through the use of the innerHTML property, but this does not work in all cases; for instance, when assigning a string of <option> elements as the innerHTML of a <select> element (a horrible problem for everyone).
In these cases I'm under the impression that it's best to use the DOM API as much as possible since, in these cases, it works and innerHTML doesn't. Unfortunately this does not appear to be a direct option in HTML_AJAX_Action; it could probably be done using insertScript(), but it would be nice if that could be avoided through a more direct implementation of the DOM API in HTML_AJAX_Action.
Test script:
---------------
function updateSelect($select_id) {
$result = new HTML_AJAX_Action();
$newoptions = '<option value="1">One</option><option value="2">Two</option><option value="3">Three</option>';
$result->insertAlert($newoptions);
$result->assignAttr($select_id, 'innerHTML', $newoptions);
return $result;
}
[2006-11-21 14:02 UTC] auroraeosrose at php dot net
Please look at the HTML_AJAX_Action class - there are three "dom-centric" methods present - createNode, replaceNode and removeNode for dom-style manipulation
If you want to append a child node use $action->createNode(
$id, $tag, $attributes, 'append') - the $id should be the id of the item you want to add a child to, the tag is the type of html tag to create, and attributes should be an array of attributes to apply to the new node.
There is also a prepend option that will push an item onto the front of the list of children, and insertBefore and insertAfter options which add the new node parallel to the node with the id you supply instead of as a child.
[2006-11-22 14:16 UTC] jazzslider at gmail dot com
I understand now. I have been using HTML_AJAX_Action based on the instructions in the tutorial (http://wiki.bluga.net/HTML_AJAX/Using%20haSerializer?), but I think the part that confused me was here:
"If you choose to append or prepend a node it will be placed at the beginning or end of the node with the id you send. If you choose insertBefore or InsertAfter it will be put right before or right after the node you specified."
I think my mind automatically equated verbage like "at the beginning...of the node" with "right before...the node", rather than realizing that the former meant "at the beginning of the specified node's list of children".
Sorry about this! I was incorrect.