overwriting elements

1 view
Skip to first unread message

Steve Onnis

unread,
Dec 3, 2008, 11:14:44 PM12/3/08
to mootool...@googlegroups.com
Question:
 
If i submit a form using ajax and the response that comes back is another form with the same id, if i replace the original form with the response data form does the old form and its id stay in memory? or does it get overwritten?

nutron

unread,
Dec 3, 2008, 11:31:29 PM12/3/08
to mootool...@googlegroups.com
It is no longer in memory.

You might check out this:



On Wed, Dec 3, 2008 at 8:15 PM, Steve Onnis (via Nabble) <ml-user%2B120788-510555256@...> wrote:
Question:
 
If i submit a form using ajax and the response that comes back is another form with the same id, if i replace the original form with the response data form does the old form and its id stay in memory? or does it get overwritten?

The MooTools Tutorial: www.mootorial.com CNET Clientside: clientside.cnet.com


View this message in context: Re: overwriting elements
Sent from the MooTools Users mailing list archive at Nabble.com.

Steve Onnis

unread,
Dec 3, 2008, 11:37:32 PM12/3/08
to mootool...@googlegroups.com
I have it getting back into the dom fine.  Just i am trying to attach some other methods and properties to the form.  They are there when the form initially loads but they dont seem to get reattached with the new form.  its driving me crazy


From: mootool...@googlegroups.com [mailto:mootool...@googlegroups.com] On Behalf Of nutron
Sent: Thursday, 4 December 2008 3:31 PM
To: mootool...@googlegroups.com
Subject: Re: overwriting elements

nutron

unread,
Dec 3, 2008, 11:53:14 PM12/3/08
to mootool...@googlegroups.com
You need to attach it again.

var attachToForm = function(form) {
   form.addEvent('submit', funciton(){
      form.send....
        ...onComplete: function(){
           attachToForm($('myNewForm'));
        }
   })
};
attachToForm(myForm);

On Wed, Dec 3, 2008 at 8:37 PM, Steve Onnis (via Nabble) <ml-user%2B120788-510555256@...> wrote:
I have it getting back into the dom fine.  Just i am trying to attach some other methods and properties to the form.  They are there when the form initially loads but they dont seem to get reattached with the new form.  its driving me crazy


From: mootools-users@... [mailto:mootools-users@...] On Behalf Of nutron

Sent: Thursday, 4 December 2008 3:31 PM
To: mootools-users@...
Subject: Re: overwriting elements

It is no longer in memory.

You might check out this:

http://www.clientcide.com/wiki/cnet-libraries/09-forms/05.1-fupdate

On Wed, Dec 3, 2008 at 8:15 PM, Steve Onnis (via Nabble) <ml-user%2B120788-510555256@...> wrote:
Question:
 
If i submit a form using ajax and the response that comes back is another form with the same id, if i replace the original form with the response data form does the old form and its id stay in memory? or does it get overwritten?

The MooTools Tutorial: www.mootorial.com CNET Clientside: clientside.cnet.com


View this message in context: Re: overwriting elements
Sent from the MooTools Users mailing list archive at Nabble.com.

Steve Onnis

unread,
Dec 4, 2008, 12:29:42 AM12/4/08
to mootool...@googlegroups.com
thats what i am doing
 
the submit event is being added fine.  just fomr properties and methods i am trying to attach to the form are not being added to the form object.
 
sorry for the big post but.....
 
 
 
window.addEvent('load', function(){
  
  if($("subscribe")) {
   
    $("subscribe").getElement("a").addEvent("click", function () {
      if (!$("site-mask")) {
        mask = createMask("enews-subscribe", "Subscribe to AGEST eNews");
       
        mask.setOpacity(0);
        mask.injectInside($$("body")[0]);
        $("cover").setOpacity(0.4);
 
        new Request.HTML({
          url: "viewmodes/subscriptions/subscribe.cfm",
          update : $("site-mask").getElement("div[class=body]"),
          evalScripts : true,
          onComplete : function () {
                  setupSubmit();
                  var fx = new Fx.Morph(mask, {
                          duration: 200,
                          wait: true,
                          onComplete : function () {
                            if ($("close-mask")) {
                              $("close-mask").addEvent("click", function () {
                                closeMask();
                                });
                              }
                            }
                          }).start({"opacity":1});
            }
          }).send();
        }
      });
    }
   
   
  function setupSubmit() {
    if ($("site-mask").getElement("div[class=body]").getElement("form")) {
      $("site-mask").getElement("div[class=body]").getElement("form").externalSubmit = true
      $("site-mask").getElement("div[class=body]").getElement("form").addEvent("submit", function (ev) {
        new Event(ev).stop();
       
        this.set("send", {
          evalScripts : true,
         
          onComplete : function (responseText) {
            $("site-mask").getElement("div[class=body]").set("html", responseText);
           
            if ($("close-mask")) {
              $("close-mask").addEvent("click", function () {
                closeMask();
                });
              }
            setupSubmit();
            }
          });
        var result = this.validator.validateForm();
               
        if (result.length == 0) {
          this.getElement("input[type=submit]").getParent().set("html", "<p align=\"center\"><strong>Processing your request..</strong><br /><img src=\"css/images/ajax-loader.gif\" /></p>");
          this.send();
          }
        });
      }
    } 
  ////////////////////////////////////////////////////////
 
  });
 
 
The first time the form loads this.validator is available but when it runs and pumps the form back into the container it is no longer available.
 
 
 
 
 

From: mootool...@googlegroups.com [mailto:mootool...@googlegroups.com] On Behalf Of nutron
Sent: Thursday, 4 December 2008 3:53 PM

To: mootool...@googlegroups.com
Subject: Re: overwriting elements

nutron

unread,
Dec 4, 2008, 12:17:03 PM12/4/08
to mootool...@googlegroups.com
1) please use pastebin for code - it's much easier - http://paste.mootools.net/

2) .getElement("div[class=body]")- you should use div.body as your selector - what you have now wouldn't match a div with class="body foo"

3) what is this.validator? where is that defined? That's not a standard element property - what's "this" in the context?

From: mootools-users@... [mailto:mootools-users@...] On Behalf Of nutron
Sent: Thursday, 4 December 2008 3:53 PM

Steve Onnis

unread,
Dec 4, 2008, 6:07:40 PM12/4/08
to mootool...@googlegroups.com
Im not trying to match class="body foo". I know that thats the class name and it works fine
 
validator is a form validation object i am attaching to the form object and gets set elsewhere.  "this" is referning to the form as "this" would inside a addEvent for a form object. 
 
I got it working.  For some reason i think the setupSubmit() was getting called too early inside the onComplete.  I moved it and all works now


From: mootool...@googlegroups.com [mailto:mootool...@googlegroups.com] On Behalf Of nutron
Sent: Friday, 5 December 2008 4:17 AM

To: mootool...@googlegroups.com
Subject: Re: overwriting elements
Reply all
Reply to author
Forward
0 new messages