Carlton Dickson wrote:
So when you say extend this means I don't need to alter the source in the controls.js right?

That is correct. Javascript's objects can be modified after creation so I just change the initialize method (and a few other things). This means you will need to put this bit of code after your Script.aculo.us code.

How do you go about defining an element that is editable with your code, with scriptaculous they obviously use

new Ajax.InPlaceEditor(element, 'url', [options]);

You can still use that but if you prefer it to not make the Ajax call and instead prefer a callback you can do:

new Ajax.InPlaceEditor(element, {
        saveText_Callback: function(form, fieldval, success, failure) {
                //...Implement your custom saving...
        }
});

Basically I add an option called "saveText_Callback" (probably not the best named but I did this a while back). This function object is responsible for doing whatever needs to happen to save this value. It is given an instance of the form and the field value. It is also given the "onComplete" and "onFailure" function objects so that it can carry out those events depending on the status of it's save operation. This allows the onComplete and onFailure event handlers to still have meaning.

The idea is that you are implementing the save yourself instead of relying on the built in Ajax call. This may mean you store the value in a hidden form field, you make your own ajax call, or perhaps you don't save at all. It's up to you.

Even after adding this modified version of Ajax.InPlaceEditor you can still use the old interface (i.e. passing a url as the second parameter and the options as a third parameter) so it does not break existing behavior.

What techniques would you use if you wanted to update a value in a table based on the value that has been entered in the editor?

If your are using my code and you don't care about saving the actual value of the inplace editor I would do something like:

new Ajax.InPlaceEditor(element, {
        saveText_Callback: function(form, fieldval, success, failure) {
                Element.update('my_table_cell', fieldval);
                success();
        }
});

Eric

_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to