PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » HTML_AJAX » Bug #6062

Problems with haSerizalizer: message.this._replaceAttr is not a function

Details

Submitted2005-11-24 20:06 UTC
Fromchristian at laakmann dot org
Assigneddavidc
StatusClosed
PackageHTML_AJAX
PHP Version5.0.4
OSWindows XP
Roadmaps(Not assigned)

Comments

[2005-11-24 20:06 UTC] christian at laakmann dot org

Description:
------------
I've written a test-program with which I tried to redo the 'clickable-text', which then transforms into a form field.

When I click on the Text a JavaScript-Error-Box (details shown in 'Actual results') appears, stating that this._replaceAttr is not a function. It points to line 1584 of the file 'auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer'. In my case this line is part of the unserialize function of HTML_AJAX_Serialize_HA, to be precise, the part in the switch statement pointing to _replaceAttr...

Test script:
---------------
// in page.class.php, class Page
function showForm($id, $value) {
$response = new HTML_AJAX_Action();
$response->replaceNode($id, 'input', array('value'=>$value, 'type'=>'text', 'onBlur'=>'javascript:showText(this.id, this.value);'));
return $response;
}

// index.php, js is created via $ahajxHelper->setupAJAX(), naturally
$ajaxHelper = new HTML_AJAX_Helper();
$ajaxHelper->serverUrl = 'auto_server.php';
$ajaxHelper->jsLibraries[] = 'haserializer';
$ajaxHelper->stubs[] = 'page';

// later, as JS, called in onClick:

function showForm(id, value) {
remotepage = new page();
remotepage.showForm(id, value);
}

Expected result:
----------------
Well.. the text should change into a form input element containing the text itself.

Actual result:
--------------
JavaScript Error Backtrace, captured via onError, HTML_AJAX_Util.quickPrint():

## Error: ##
message:this._replaceAttr is not a function fileName:http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer lineNumber:1584 stack:("[{\"action\":\"replace\",\"id\":\"name\",\"attributes\":true}]")@http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer:1584 ()@http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer:943 ()@http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer:842 ()@http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer:511 ([object Object])@http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer:250 ("showForm",[object Object])@http://localhost/ajax-test/auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,Loading,JSON,haserializer:1034 ("name","Test")@http://localhost/ajax-test/auto_server.php?stub=page:11 showForm("name","Test")@http://localhost/ajax-test/:21 onclick([object MouseEvent])@http://localhost/ajax-test/:1 @:0 name:TypeError

[2005-11-26 17:20 UTC] christian at laakmann dot org

After having digged through the AJAX Code more thoroughly, I found some errors:

1. the function to replace nodes was named wrongly in haSerializer.js (_replaceAttr instead of _replaceNode). In the SVN this has been fixed already, though.

2. the function replaceNode in Action.php is not using it's tag argument:

// As it is now:
function replaceNode($id, $tag, $attribute)
{
$this->_actions[] = array(
'action' => 'replace',
'id' => $id,
// here something along the lines of
// 'tag' => $tag,
// should be added
'attributes' => settype($attribute, 'array'),
);
return;
}

So, the solution to this bug has been found, but there's another one :-)

It seems the attributes-array is not forwarded to Javascript. Haven't yet found out why...

Greetings Christian

[2005-11-26 17:27 UTC] christian at laakmann dot org

I have to correct myself...

the _replaceNode function in haSerializer.js ist named correctly, but the switch-statement forwards the action to _replaceAttr, which is, of course, wrong.

[2005-11-27 17:34 UTC] christian at laakmann dot org

I have found the solution to this whole replaceNode issue... Seems there was some late-night programming at work :-)

I've uploaded the two file Action.php and haSerializer.js here: http://www.laakmann.org/HTML_AJAX/

There are 3 things change:

haSerializer:
- line 44: changed _replaceAttr to _replaceNode, was referencing the wrong function

- line 219 and following: there is a problem with setting innerHTML and value using setAttribute. The original Programmer had found a solution but forgot to implement it in _replaceNode aswell

Action.php
- below line 156: I added the line 'tag' => $tag, which has been forgotten