You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Lenny Primak <lp...@hope.nyc.ny.us> on 2011/04/18 05:53:18 UTC

How to get the Zone ID from a form (or a submit button)

Hi all,

I have a mixin that watches for zone updates.
This mixin is set up on a submit button for a form.
I cannot fund a way to make the mixin fetch the zone from an underlying form.
So, as a workaround I am forced to specify the same zone twice.  Any hints
on how I can get the zone inside the mixin from the underlying form?

 <form t:type="form" zone="myZone">
	<h1>Press 
	<button t:type="submit" value="Here" event="doThis" t:mixins="DisableAfterSubmit" zone="myZone"> !!! I DO NOT WANT TO SPECIFY SAME ZONE TWICE
	  <t:remove>Here</t:remove>
	</button>
	to Do this!</h1>
  </form>


Thanks!

--------------------------

@Import(library="context:scripts/DisableAfterSubmit.js")
public class DisableAfterSubmit
{
    @AfterRender
    void addDisabler()
    {
        js.addScript("new DisableAfterSubmit('%s', '%s', '%s');",
                submitButton.getClientId(), fs.getClientId(), zone);
    }
    
    
    @Environmental private JavaScriptSupport js;
    @InjectContainer private ClientElement submitButton;
    @Environmental private FormSupport fs;
    @Parameter(required=true, defaultPrefix=BindingConstants.LITERAL) private String zone;
}
--------------------------------

/**
 * Disable Submit button after AJAX Form Submission
 */

var DisableAfterSubmit = Class.create();
DisableAfterSubmit.prototype = {
		initialize: function(elementId, formId, zoneId) {
			this.formId = formId;
			this.elementId = elementId;
			this.zoneId = zoneId;

			Event.observe($(elementId), 'click',
					this.doDisable.bindAsEventListener(this));
			
			Event.observe($(zoneId), Tapestry.ZONE_UPDATED_EVENT,
					this.doEnable.bindAsEventListener(this));
		},

		doDisable: function(e) {
			$(this.elementId).disable();
			$(this.formId).onsubmit();
		},
		
		doEnable: function(e) {
			$(this.elementId).enable();
		}
};



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to get the Zone ID from a form (or a submit button)

Posted by Lenny Primak <lp...@hope.nyc.ny.us>.
I figured it out!.  findZoneManager wasn't finding the zone because it was getting called
during initialization before the zone actually gets instantiated by tapestry's init javascript.
I moved the findZoneManager code into the actual click event, and not it works perfectly.
Thanks!

Now I need to do what I've been avoiding all my professional career - learn JS :)

On Apr 18, 2011, at 12:43 AM, Taha Hafeez wrote:

> Hi
> 
> Did you try Tapestry.findZoneManager(formId);
> 
> regards
> Taha
> 
> On Mon, Apr 18, 2011 at 9:23 AM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:
> 
>> Hi all,
>> 
>> I have a mixin that watches for zone updates.
>> This mixin is set up on a submit button for a form.
>> I cannot fund a way to make the mixin fetch the zone from an underlying
>> form.
>> So, as a workaround I am forced to specify the same zone twice.  Any hints
>> on how I can get the zone inside the mixin from the underlying form?
>> 
>> <form t:type="form" zone="myZone">
>>       <h1>Press
>>       <button t:type="submit" value="Here" event="doThis"
>> t:mixins="DisableAfterSubmit" zone="myZone"> !!! I DO NOT WANT TO SPECIFY
>> SAME ZONE TWICE
>>         <t:remove>Here</t:remove>
>>       </button>
>>       to Do this!</h1>
>> </form>
>> 
>> 
>> Thanks!
>> 
>> --------------------------
>> 
>> @Import(library="context:scripts/DisableAfterSubmit.js")
>> public class DisableAfterSubmit
>> {
>>   @AfterRender
>>   void addDisabler()
>>   {
>>       js.addScript("new DisableAfterSubmit('%s', '%s', '%s');",
>>               submitButton.getClientId(), fs.getClientId(), zone);
>>   }
>> 
>> 
>>   @Environmental private JavaScriptSupport js;
>>   @InjectContainer private ClientElement submitButton;
>>   @Environmental private FormSupport fs;
>>   @Parameter(required=true, defaultPrefix=BindingConstants.LITERAL)
>> private String zone;
>> }
>> --------------------------------
>> 
>> /**
>> * Disable Submit button after AJAX Form Submission
>> */
>> 
>> var DisableAfterSubmit = Class.create();
>> DisableAfterSubmit.prototype = {
>>               initialize: function(elementId, formId, zoneId) {
>>                       this.formId = formId;
>>                       this.elementId = elementId;
>>                       this.zoneId = zoneId;
>> 
>>                       Event.observe($(elementId), 'click',
>> 
>> this.doDisable.bindAsEventListener(this));
>> 
>>                       Event.observe($(zoneId),
>> Tapestry.ZONE_UPDATED_EVENT,
>> 
>> this.doEnable.bindAsEventListener(this));
>>               },
>> 
>>               doDisable: function(e) {
>>                       $(this.elementId).disable();
>>                       $(this.formId).onsubmit();
>>               },
>> 
>>               doEnable: function(e) {
>>                       $(this.elementId).enable();
>>               }
>> };
>> 
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>> 
>> 


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
For additional commands, e-mail: users-help@tapestry.apache.org


Re: How to get the Zone ID from a form (or a submit button)

Posted by Taha Hafeez <ta...@gmail.com>.
Hi

Did you try Tapestry.findZoneManager(formId);

regards
Taha

On Mon, Apr 18, 2011 at 9:23 AM, Lenny Primak <lp...@hope.nyc.ny.us>wrote:

> Hi all,
>
> I have a mixin that watches for zone updates.
> This mixin is set up on a submit button for a form.
> I cannot fund a way to make the mixin fetch the zone from an underlying
> form.
> So, as a workaround I am forced to specify the same zone twice.  Any hints
> on how I can get the zone inside the mixin from the underlying form?
>
>  <form t:type="form" zone="myZone">
>        <h1>Press
>        <button t:type="submit" value="Here" event="doThis"
> t:mixins="DisableAfterSubmit" zone="myZone"> !!! I DO NOT WANT TO SPECIFY
> SAME ZONE TWICE
>          <t:remove>Here</t:remove>
>        </button>
>        to Do this!</h1>
>  </form>
>
>
> Thanks!
>
> --------------------------
>
> @Import(library="context:scripts/DisableAfterSubmit.js")
> public class DisableAfterSubmit
> {
>    @AfterRender
>    void addDisabler()
>    {
>        js.addScript("new DisableAfterSubmit('%s', '%s', '%s');",
>                submitButton.getClientId(), fs.getClientId(), zone);
>    }
>
>
>    @Environmental private JavaScriptSupport js;
>    @InjectContainer private ClientElement submitButton;
>    @Environmental private FormSupport fs;
>    @Parameter(required=true, defaultPrefix=BindingConstants.LITERAL)
> private String zone;
> }
> --------------------------------
>
> /**
>  * Disable Submit button after AJAX Form Submission
>  */
>
> var DisableAfterSubmit = Class.create();
> DisableAfterSubmit.prototype = {
>                initialize: function(elementId, formId, zoneId) {
>                        this.formId = formId;
>                        this.elementId = elementId;
>                        this.zoneId = zoneId;
>
>                        Event.observe($(elementId), 'click',
>
>  this.doDisable.bindAsEventListener(this));
>
>                        Event.observe($(zoneId),
> Tapestry.ZONE_UPDATED_EVENT,
>
>  this.doEnable.bindAsEventListener(this));
>                },
>
>                doDisable: function(e) {
>                        $(this.elementId).disable();
>                        $(this.formId).onsubmit();
>                },
>
>                doEnable: function(e) {
>                        $(this.elementId).enable();
>                }
> };
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>