#18 new
crankshaft

Ajax.InPlaceEditor doesn't support ajaxOptions onComplete

Reported by crankshaft | June 5th, 2008 @ 10:32 AM

I'm using CakePHP and its Ajax Helper in our project. To invoke the editor, you use the syntax below:

<?php echo $ajax->editor('myDivId', '/my_controller/updateField/field_name', array('onComplete'=>'function(){doSomething();}', 'highlightcolor'=>'#cccccc', 'highlightendcolor'=>'#959595')); ?>

This should generate the following JS:

new Ajax.InPlaceEditor('myDivId', '/my_controller/updateField/field_name', {onComplete:function(){doSomething();}, highlightcolor:'#cccccc', highlightendcolor:'#959595', ajaxOptions:{asynchronous:true, evalScripts:true}});

But due to a bug in CakePHP it completely strips out the onComplete stuff.

However, Cake supports another 'complete' option documented here. You use it like this:

<?php echo $ajax->editor('myDivId', '/my_controller/updateField/field_name', array('complete'=>'doSomething();', 'highlightcolor'=>'#cccccc', 'highlightendcolor'=>'#959595')); ?>

The code above generates the following JS:

new Ajax.InPlaceEditor('myDivId', '/my_controller/updateField/field_name', {highlightcolor:'#cccccc', highlightendcolor:'#959595', ajaxOptions:{asynchronous:true, evalScripts:true, onComplete:function(request, json) {doSomething();}}});

That looks promising, however, the onComplete in the ajaxOptions NEVER FIRES. I got it to work by commenting out line 634 in controls.js (scriptaculous 1.8.1):

      Object.extend(options, {
        parameters: params,
        //onComplete: this._boundWrapperHandler,
        onFailure: this._boundFailureHandler
      });

...but I don't think that's a good solution. :)

Comments and changes to this ticket

  • ronin-15560 (at lighthouseapp)

    ronin-15560 (at lighthouseapp) June 12th, 2008 @ 08:47 AM

    • Assigned user changed from “ronin-15560 (at lighthouseapp)” to “Christophe Porteneuve”
  • crankshaft

    crankshaft June 18th, 2008 @ 03:25 PM

    I couldn't afford waiting any longer, so I had to fix this myself. :)

    The problem lies between lines 631-636 in control.js:

          var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
          Object.extend(options, {
            parameters: params,
            onComplete: this._boundWrapperHandler,
            onFailure: this._boundFailureHandler
          });
    

    Now, if this.options.ajaxOptions['onComplete'] != null, it gets written over when extending the options object. The solution is to "merge" the user's custom onComplete functions with this._boundWrapperHandler. I don't know if there's a clean way to do this, but I solved it like this:

          var options = Object.extend({ evalScripts: true }, this.options.ajaxOptions);
          
          // patch begins
          var oc = new Function();
          for (var i in options) {
          	if (i == "onComplete") {
          		oc = options[i];
          	}
          }
          Object.extend(options, {
            parameters: params,
            onComplete: function() { this._boundWrapperHandler(); oc(); }.bind(this),
            onFailure: this._boundFailureHandler
          });
          // patch ends
    

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

script.aculo.us is an open-source JavaScript framework for visual effects and interface behaviours.
<br/><b>Source available from github</b>
The Git repository resides at:
<a href="http://github.com/madrobby/scriptaculous">http://github.com/madrobby/scriptaculous</a>
<br/>Check out the current development trunk with:
<code>git clone git://github.com/madrobby/scriptaculous.git</code>
<br/>As <b>script.aculo.us 1.xx is feature-frozen</b>, this development trunk is for <b>bugfixes only</b>.
<br/>New development should happen only for
<b>script.aculo.us 2</b>.
<br/><b>Creating a bug report</b>
When creating a bug report, be sure to include as much relevant information as possible. Post a an example that shows off the problem. Preferably, <b>alter the unit tests</b> and show through either changed or added tests how the expected behavior is not occuring.

People watching this ticket

Pages