Sylvain Wallez wrote:
>> My goal is to let a user insert a "Form Fragment" build from a
>> template XML file. But I haven't been able to do it yet although I see
>> no reason, my Cocoon understanding appart, why it should not be
possible.
>
>
> I see. What you needed is probably a partial binding of the form, i.e.
> binding only a widget (I suppose there must be fd:union somewhere) with
> the fragment, instead of binding the full form.
I extended Form.js a while ago to support multiple bindings per form, so
that I could selectively bind data in/out on parts of a form. There's
nothing in the CForms architecture that requires only one binding per
form except for the way Form.js is implemented, and since JavaScript
makes it easy to override implementations I just had to insert the
following at the top of my flowscript file (right below the
cocoon.load() of Form.js):
// Some patchwork to add support for multiple bindings per form:
Form.prototype._orig_createBinding = Form.prototype.createBinding;
Form.prototype.createBinding = function(bindingURI) {
this._orig_createBinding(bindingURI);
return this.binding;
};
Form.prototype._orig_load = Form.prototype.load;
Form.prototype.load = function(obj, binding) {
if(binding != null) this.binding = binding;
this._orig_load(obj);
};
Form.prototype._orig_save = Form.prototype.save;
Form.prototype.save = function(obj, binding) {
if(binding != null) this.binding = binding;
this._orig_save(obj);
};
This makes two changes: first, form.createBinding() returns a reference
to the Binding object it creates (you can call this method multiple
times to create multiple bindings); and second, it allows you to pass a
reference to one of those Binding objects as the second argument to
.load() and .save() so it knows which one to use. That second argument
is optional so it still behaves in a backward-compatible way if you only
have one binding.
I use this in one of my projects to load new data into one part of my
form from a widget event handler (which is super-nice when AJAX is
turned on!). This sounds very similar to what Patrick is wanting to do,
so maybe this code will be helpful to him. For that matter, is this
perhaps a feature you might be interested in putting in the main
codebase? If so please feel free, if not I'll probably make a wiki
entry or something.
--Jason
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]