You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Norman Franke <fr...@bethzur.com> on 2011/07/07 23:26:56 UTC

5.2 AJAX Forms

I'm attempting to display a ModalBox dialog with a form in it and  
submit that form via AJAX. I've tried a few components people have  
posted to the list. The display of the form works great, but Tapestry  
refuses to make it submit via AJAX.

I want to do this so I can display validation errors in the dialog,  
which are otherwise ignored.

Has anyone got this to work with Tapestry 5.2.5?

-Norman


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


Re: 5.2 AJAX Forms

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

On Fri, Jul 8, 2011 at 9:37 PM, Norman Franke <no...@myasd.com> wrote:

> I did, but I apparently used a much more recent version of ModalBox. The
> version you are using is very, very old. They changed the "onContentLoaded"
> callback to "afterLoad" so the form scripts weren't being called.
>
> Changed

https://github.com/tawus/tawus/issues/3



> However, there are several other issues with the code you mentioned.
>
> 1. Form error handling doesn't work because the dialog doesn't resize.
> (Later versions of ModalBox have a resizeToContent method.) Using my
> modified version of your script, I can get resize working if I put in an
> inline script.
>
> resize happens on each ajax call

https://github.com/tawus/tawus/issues/4


> 2. Also, if you hit cancel, the form is inserted into the DOM and you see
> it in on your page.
>
> Not sure about it, but you can check if this is resolved


> 3. There doesn't appear to be a way to submit and close only if there were
> no errors.
>
> https://github.com/tawus/tawus/issues/5


> 4. Using a t:submit with mode="CANCEL" doesn't work, It submits anyway.
>
> mode="CANCEL" only disabled client side validation not server side

Norman Franke
> Answering Service for Directors, Inc.
> www.myasd.com
>
>
You can check if there are any more modifications required.

I would appreciate if you add the issues at
https://github.com/tawus/tawus/issues in case you find more.


>
>
>
> On Jul 7, 2011, at 9:22 PM, Taha Hafeez wrote:
>
>  Hi
>>
>> Have you tried the modaldialog at
>> https://github.com/tawus/**tawus/tree/master/tawus-addons<https://github.com/tawus/tawus/tree/master/tawus-addons>
>>
>> Here is an example
>>
>> public class ModalDialogWithForm
>> {
>>  @Property
>>  @Persist(PersistenceConstants.**FLASH)
>>  private String name;
>>
>>  @Property
>>  @Persist(PersistenceConstants.**FLASH)
>>  private String address;
>>
>>  @Inject
>>  private Block formBlock;
>>
>>  @InjectComponent
>>  private Zone zone;
>>
>>  @SuppressWarnings("unused")
>>  @Property
>>  private String message;
>>
>>  void onSuccess()
>>  {
>>     message = String.format("Hello %s, your address is %s", name,
>> address);
>>  }
>>
>>  void onFailure()
>>  {
>>     message = String.format("Submission failed");
>>  }
>>
>>  Object onSubmit()
>>  {
>>     return zone;
>>  }
>>
>>  Block onShowDialog()
>>  {
>>     return formBlock;
>>  }
>> }
>>
>> <html xmlns:t='http://tapestry.**apache.org/schema/tapestry_5_**1_0.xsd<http://tapestry.apache.org/schema/tapestry_5_1_0.xsd>
>> '>
>>  <body>
>>     <a t:type='tawus/modaldialog'>**Show Dialog with form</a>
>>
>>     <t:block t:id='formBlock'>
>>        <div t:type='zone' t:id='zone' id='zone'>
>>           <div
>> style='font-size:12px;font-**weight:bold;color:green'>${**message}</div>
>>           <form t:type='form' t:zone='zone'>
>>              <t:errors />
>>              <label t:type='label' for='name'>Name :
>>                 <input t:type='textfield' t:id='name'
>> t:validate='required'/>
>>              </label>
>>              <br />
>>
>>              <label t:type='label' for='address'>Address:
>>                 <textarea t:type='textarea' t:id='address'
>> t:validate='required'></**textarea>
>>              </label>
>>
>>               <br/>
>>              <input type='submit' value='Submit' />
>>           </form>
>>        </div>
>>     </t:block>
>>
>>  </body>
>> </html>
>>
>> regards
>> Taha
>>
>>
>> On Fri, Jul 8, 2011 at 2:56 AM, Norman Franke <fr...@bethzur.com> wrote:
>>
>>  I'm attempting to display a ModalBox dialog with a form in it and submit
>>> that form via AJAX. I've tried a few components people have posted to the
>>> list. The display of the form works great, but Tapestry refuses to make
>>> it
>>> submit via AJAX.
>>>
>>> I want to do this so I can display validation errors in the dialog, which
>>> are otherwise ignored.
>>>
>>> Has anyone got this to work with Tapestry 5.2.5?
>>>
>>> -Norman
>>>
>>>
>>> ------------------------------****----------------------------**
>>> --**---------
>>> To unsubscribe, e-mail: users-unsubscribe@tapestry.**a**pache.org<http://apache.org>
>>> <us...@tapestry.apache.org>
>>> >
>>>
>>> For additional commands, e-mail: users-help@tapestry.apache.org
>>>
>>>
>>>
>>
>> --
>> regards
>> Tawus
>> tawus.wordpress.com
>>
>
>


-- 
regards
Tawus
tawus.wordpress.com

Re: 5.2 AJAX Forms

Posted by Norman Franke <no...@myasd.com>.
I did, but I apparently used a much more recent version of ModalBox.  
The version you are using is very, very old. They changed the  
"onContentLoaded" callback to "afterLoad" so the form scripts weren't  
being called.

However, there are several other issues with the code you mentioned.

1. Form error handling doesn't work because the dialog doesn't resize.  
(Later versions of ModalBox have a resizeToContent method.) Using my  
modified version of your script, I can get resize working if I put in  
an inline script.

2. Also, if you hit cancel, the form is inserted into the DOM and you  
see it in on your page.

3. There doesn't appear to be a way to submit and close only if there  
were no errors.

4. Using a t:submit with mode="CANCEL" doesn't work, It submits anyway.

Norman Franke
Answering Service for Directors, Inc.
www.myasd.com



On Jul 7, 2011, at 9:22 PM, Taha Hafeez wrote:

> Hi
>
> Have you tried the modaldialog at
> https://github.com/tawus/tawus/tree/master/tawus-addons
>
> Here is an example
>
> public class ModalDialogWithForm
> {
>   @Property
>   @Persist(PersistenceConstants.FLASH)
>   private String name;
>
>   @Property
>   @Persist(PersistenceConstants.FLASH)
>   private String address;
>
>   @Inject
>   private Block formBlock;
>
>   @InjectComponent
>   private Zone zone;
>
>   @SuppressWarnings("unused")
>   @Property
>   private String message;
>
>   void onSuccess()
>   {
>      message = String.format("Hello %s, your address is %s", name,
> address);
>   }
>
>   void onFailure()
>   {
>      message = String.format("Submission failed");
>   }
>
>   Object onSubmit()
>   {
>      return zone;
>   }
>
>   Block onShowDialog()
>   {
>      return formBlock;
>   }
> }
>
> <html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_1_0.xsd'>
>   <body>
>      <a t:type='tawus/modaldialog'>Show Dialog with form</a>
>
>      <t:block t:id='formBlock'>
>         <div t:type='zone' t:id='zone' id='zone'>
>            <div
> style='font-size:12px;font-weight:bold;color:green'>${message}</div>
>            <form t:type='form' t:zone='zone'>
>               <t:errors />
>               <label t:type='label' for='name'>Name :
>                  <input t:type='textfield' t:id='name'
> t:validate='required'/>
>               </label>
>               <br />
>
>               <label t:type='label' for='address'>Address:
>                  <textarea t:type='textarea' t:id='address'
> t:validate='required'></textarea>
>               </label>
>
>                <br/>
>               <input type='submit' value='Submit' />
>            </form>
>         </div>
>      </t:block>
>
>   </body>
> </html>
>
> regards
> Taha
>
>
> On Fri, Jul 8, 2011 at 2:56 AM, Norman Franke <fr...@bethzur.com>  
> wrote:
>
>> I'm attempting to display a ModalBox dialog with a form in it and  
>> submit
>> that form via AJAX. I've tried a few components people have posted  
>> to the
>> list. The display of the form works great, but Tapestry refuses to  
>> make it
>> submit via AJAX.
>>
>> I want to do this so I can display validation errors in the dialog,  
>> which
>> are otherwise ignored.
>>
>> Has anyone got this to work with Tapestry 5.2.5?
>>
>> -Norman
>>
>>
>> ------------------------------**------------------------------ 
>> **---------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<users-unsubscribe@tapestry.apache.org 
>> >
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> -- 
> regards
> Tawus
> tawus.wordpress.com


Re: 5.2 AJAX Forms

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

Have you tried the modaldialog at
https://github.com/tawus/tawus/tree/master/tawus-addons

Here is an example

public class ModalDialogWithForm
{
   @Property
   @Persist(PersistenceConstants.FLASH)
   private String name;

   @Property
   @Persist(PersistenceConstants.FLASH)
   private String address;

   @Inject
   private Block formBlock;

   @InjectComponent
   private Zone zone;

   @SuppressWarnings("unused")
   @Property
   private String message;

   void onSuccess()
   {
      message = String.format("Hello %s, your address is %s", name,
address);
   }

   void onFailure()
   {
      message = String.format("Submission failed");
   }

   Object onSubmit()
   {
      return zone;
   }

   Block onShowDialog()
   {
      return formBlock;
   }
}

<html xmlns:t='http://tapestry.apache.org/schema/tapestry_5_1_0.xsd'>
   <body>
      <a t:type='tawus/modaldialog'>Show Dialog with form</a>

      <t:block t:id='formBlock'>
         <div t:type='zone' t:id='zone' id='zone'>
            <div
style='font-size:12px;font-weight:bold;color:green'>${message}</div>
            <form t:type='form' t:zone='zone'>
               <t:errors />
               <label t:type='label' for='name'>Name :
                  <input t:type='textfield' t:id='name'
t:validate='required'/>
               </label>
               <br />

               <label t:type='label' for='address'>Address:
                  <textarea t:type='textarea' t:id='address'
t:validate='required'></textarea>
               </label>

                <br/>
               <input type='submit' value='Submit' />
            </form>
         </div>
      </t:block>

   </body>
</html>

regards
Taha


On Fri, Jul 8, 2011 at 2:56 AM, Norman Franke <fr...@bethzur.com> wrote:

> I'm attempting to display a ModalBox dialog with a form in it and submit
> that form via AJAX. I've tried a few components people have posted to the
> list. The display of the form works great, but Tapestry refuses to make it
> submit via AJAX.
>
> I want to do this so I can display validation errors in the dialog, which
> are otherwise ignored.
>
> Has anyone got this to work with Tapestry 5.2.5?
>
> -Norman
>
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.**apache.org<us...@tapestry.apache.org>
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
regards
Tawus
tawus.wordpress.com