On 7/16/07, Bob Ippolito <[EMAIL PROTECTED]> wrote:
>
> On 7/16/07, MerlinTheCat <[EMAIL PROTECTED]> wrote:
> >
> > Hi, I'm well versed in JS - but I've been struggling to understand
> > MochiKit for a couple of days... help from anyone who can clear my
> > brainblock would be appreciated. Thanks.
> >
> > I'm trying to add a form on the page dynamically. The H1 and [object
> > Object] form? gets displayed on the page... but I can't see the form
> > or access any of it's fields or submit it???
> >
> > Here's my code:
> >
> >
> > MochiKit.DOM.withWindow(self.window, MochiKit.Base.bind( function() {
> >
> >         var doc = MochiKit.DOM.currentDocument();
> >         MochiKit.DOM.appendChildNodes(doc.body, H1(null,"This gets added
> > OK"));
> >
> >         var formObj = MochiKit.DOM.FORM({"id":"myForm",
> > "action":"test01.asp", "method":"post"}, {"inputs": [{"type":"text",
> > "id":"field1", "name":"field1", "value":"newval"}, {"type":"submit",
> > "name":"mySubmit", "value":"mySubmit"}]});
> >
> >         MochiKit.DOM.appendChildNodes(doc.body, formObj);
> >
> > alert(doc.body.formObj.field1);  // this indicates undefined?
> > alert(doc.formObj.field1);  // this indicates undefined?
> >
> > }, this));
>
> That's because the code you wrote doesn't make any sense. {"inputs": [
> ... ]} isn't going to do anything. You need to do the same thing
> you're doing with FORM, except with INPUT.
>
> FORM(attrs, INPUT(attrs), INPUT(attrs), ...)
>
> -bob
>
You should try getting a DOM inspector. It's extremely useful for
working out what is and isn't being produced in complex DOM creation
code.  Firebug has a good one.

Also, as Bob said, the functions FORM, INPUT, etc work on a
per-element basis, since they are just partially executed calls to
createDOM. (eg: FORM == partial(createDOM, "FORM") )

createDOM, and hence all these functions, takes two arguments after
the DOM element type is specified: the attributes of the element (as a
dictionary), and the elements to nest within it (as an Array). The
nested elements need to either be constructed DOM objects, or objects
that can be coerced into DOM objects, such as strings.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"MochiKit" group.
To post to this group, send email to mochikit@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/mochikit?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to