Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Is it possible to execute behavior function for element from outside of this behavior?

View Parsed - Show only message text

MIME-Version: 1.0
Received: by 10.100.106.12 with SMTP id e12mr583561anc.28.1243423990533; Wed, 
	27 May 2009 04:33:10 -0700 (PDT)
Date: Wed, 27 May 2009 04:33:10 -0700 (PDT)
In-Reply-To: <e5f7d6a7-f56c-4d32-b9c3-588b3dc93a36@a7g2000yqk.googlegroups.com>
X-IP: 81.226.180.193
References: <e5f7d6a7-f56c-4d32-b9c3-588b3dc93a36@a7g2000yqk.googlegroups.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_7; en-us) 
	AppleWebKit/528.18.1 (KHTML, like Gecko) Version/4.0 Safari/528.17,gzip(gfe),gzip(gfe)
Message-ID: <52b3cc83-e82b-424c-b423-25fdbeb47725@j32g2000yqh.googlegroups.com>
Subject: Re: Is it possible to execute behavior function for element from 
	outside of this behavior?
From: MRoderick <roderick.mor...@gmail.com>
To: Low Pro <low-pro@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

On 27 May, 11:33, szimek <szi...@gmail.com> wrote:
> Hi,
>
> I made a behavior for span elements that simply toggle themselfes
> between add/cancel state and additionally toggle some element on the
> page (i.e. a form) on onclick event -http://gist.github.com/118542.
>
> It works fine, but the problem is when this is used to show i.e. a
> form. In this case I'd like onclick event handler to be executed when
> the form is submitted, so that I can hide the form and update span
> element. The main problem is that I can't simply fire onclick event on
> span element, which would solve the problem.
>
> Do you have any other ideas how to solve it?

Assuming the form and the span tags are closely related, why not just
create the behavior on a containing element?

Then you can have an internal function in the behavior, that can be
called from both onclick and onsubmit events.

If you use event delegation with Low Pro, it's actually quite simple.

I recently gave a very brief intro to Low Pro at a local JavaScript
meetup, and for that purpose I created a small behavior for a form,
that has both an onsubmit event listener as well as an event delegate.
You can check out the details http://roderick.dk/blog/2009/05/07/introduction-to-low-pro-for-prototype/
and from studying the example a bit, I am pretty sure it becomes clear
how to create behaviors that use containing elements.

/Morgan

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google