2010年2月6日星期六

Re: [fw-mvc] Zend_Dojo - How to get the value of an Editor dijit

-- Nathan Garlington <garlinto@gmail.com> wrote
(on Friday, 05 February 2010, 05:46 PM -0700):
> I have an instance of Zend_Dojo_Form that I use to update my online
> inventory. All of the form fields are dijits and
>
> var values = diji.byId('myForm').attr('value');
>
> ...does indeed collect all of the values as a js object. However, the
> value of the Editor is not included. Looking at the markup, there is a
> hidden input with the id specified in the form ('features'), and the
> actual textarea element has an id of "features-Editor". So, I have
> this bit of code to make sure I have all of the form values for the
> xhr payload:
>
> var values = diji.byId('myForm').attr('value');
> values.features = diji.byId('features-Editor').attr('value');
>
> ...and now I have all of the values of the form elements.
>
> I haven't done it yet, but I am assuming that POSTing the form via
> HTTP will include all of the form values, at which point I can call
> $form->getValues() and have access to everything. But since the form,
> like many others I have designed, is being submitted via xhr, is the
> behavior noted above intended, or a by-product of getting the Editor
> widget to work via Zend_Dojo_Form and it's dijit decorators? I've run
> into this "issue" a few times now and finally decided to ask about it.
> I guess what I'm saying is that I would really like the statement
>
> var values = diji.byId('myForm').attr('value');
>
> ...to always give all the form values from a Zend_Dojo_Form. Am I just
> being lazy or am I not doing something right?

The issue is in how Dojo's Editor dijit works.

Editor cannot decorate any true HTML form elements; it only works
correctly if it is built out of a plain block element, such as a <div>.
As such, when you submit a form via standard HTML form semantics, the
value will not be present. To get the value, you need to hook into the
onSubmit event, pull the value, and inject it into a form element
somewhere -- and hence the hidden form element hack present in ZF's
implementation.

This is also true if you want to use
dijit.byId('some-form').attr('value') -- the element simply will not be
present, even though it _is_ in the form, because it is not a
traditional form element.

One thing you could do is to extend dijit.form.Form to allow specifying
Editor elements in the constructor (or via attributes), and then
create a getValues method that gets both form values as well as the
Editor values.

--
Matthew Weier O'Phinney
Project Lead | matthew@zend.com
Zend Framework | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

没有评论: