You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Joost Schouten (ml)" <jo...@jsportal.com> on 2013/07/11 13:16:28 UTC

FormFragment validates on the server even when not visible

Hi,

I'm using a FormFragment triggered by two Radio's in a RadioGroup. This all
works fine and validation works as expected. The hidden Fragment is ignored
when the form is submitted. Except for one situation:

when I load the Form and containing FormFragment's in a Zone and use the
visible attribute on the FormFragment to hide one of them due to a
preselected Radio, the server will validate the fields in the Hidden
FormFragment as well. If I select the Radio's back and forth it works as
expected. When debugging I noticed the ProcessSubmission ComponentActions
are executed where they are not when the formfragment is ignored as
expected. Also the t:formdate is longer in my failing case as opposed to
the scenario where it ignores my hidden fields. This leads me to believe
there is some sort of javascript initialization call not being called in my
failing case.

Has anyone seen this before? And clues on how to solve it? I'm on Tap 5.3.6

Thanks,
Joost

some of my code:

@Component(id = "paymentTypeRadioGroup", parameters = {"value=paymentType",

 "label=message:components.entities.EntitiesCreditCard.payByTypeLabel",

 "validate=required"})

private RadioGroup paymentTypeRadioGroup;


  @Mixins("TriggerFragment")

@Component(id = "payByCreditCardRadio", parameters = {
"value=literal:CREDIT_CARD",

 "label=message:components.entities.EntitiesCreditCard.payByCreditCard",

 "fragment=creditCardBlock"})

private Radio payByCreditCardRadio;


 @Mixins("TriggerFragment")

@Component(id = "payByInvoiceRadio", parameters = {
"value=literal:MANUAL_INVOICE",

 "label=message:components.entities.EntitiesCreditCard.payByInvoice",

 "fragment=manualInvoiceBlock"})

private Radio payByInvoiceRadio;


  @Component(id = "creditCardBlock", parameters = {

 "visible=prop:showCreditCardBlock",

 "alwaysSubmit=literal:false"})

private FormFragment creditCardBlock;


 @Component(id = "manualInvoiceBlock", parameters = {

 "visible=prop:showManualInvoiceBlock",

 "alwaysSubmit=literal:false"})

private FormFragment manualInvoiceBlock;

Re: FormFragment validates on the server even when not visible

Posted by "Joost Schouten (mailing lists)" <jo...@jsportal.com>.
Hi,

Thanks for your help. Our mails must have crossed :)

isDeepVisible() does indeed seem to be setting the disabled attribute of the hidden form field! I did read the docs here but in all honesty they still don't make a lot of sense to me. I'll have a play with it as it sure sounds a bit more elegant than my solution in my previous mail :)

Thanks for your help,
Joost



On Jul 11, 2013, at 10:45 PM, Yunhua Sang wrote:

> I have the similar problem; I thinks it's because the FormFragment renders
> a hidden element, when the zone gets refreshed, the hidden element's
> disable property is set to be true, which is invalid, then the elements
> within the FromFragment get submitted  I guess it's related to
> isDeepVisible() Javascript function. Please correct me if I am wrong.
> 
> Probably you could specify the visibleBound property of the FormFragment,
> to override the default behavior.
> 
> 
> 
> 
> 
> On Thu, Jul 11, 2013 at 7:16 AM, Joost Schouten (ml)
> <jo...@jsportal.com>wrote:
> 
>> Hi,
>> 
>> I'm using a FormFragment triggered by two Radio's in a RadioGroup. This all
>> works fine and validation works as expected. The hidden Fragment is ignored
>> when the form is submitted. Except for one situation:
>> 
>> when I load the Form and containing FormFragment's in a Zone and use the
>> visible attribute on the FormFragment to hide one of them due to a
>> preselected Radio, the server will validate the fields in the Hidden
>> FormFragment as well. If I select the Radio's back and forth it works as
>> expected. When debugging I noticed the ProcessSubmission ComponentActions
>> are executed where they are not when the formfragment is ignored as
>> expected. Also the t:formdate is longer in my failing case as opposed to
>> the scenario where it ignores my hidden fields. This leads me to believe
>> there is some sort of javascript initialization call not being called in my
>> failing case.
>> 
>> Has anyone seen this before? And clues on how to solve it? I'm on Tap 5.3.6
>> 
>> Thanks,
>> Joost
>> 
>> some of my code:
>> 
>> @Component(id = "paymentTypeRadioGroup", parameters = {"value=paymentType",
>> 
>> "label=message:components.entities.EntitiesCreditCard.payByTypeLabel",
>> 
>> "validate=required"})
>> 
>> private RadioGroup paymentTypeRadioGroup;
>> 
>> 
>>  @Mixins("TriggerFragment")
>> 
>> @Component(id = "payByCreditCardRadio", parameters = {
>> "value=literal:CREDIT_CARD",
>> 
>> "label=message:components.entities.EntitiesCreditCard.payByCreditCard",
>> 
>> "fragment=creditCardBlock"})
>> 
>> private Radio payByCreditCardRadio;
>> 
>> 
>> @Mixins("TriggerFragment")
>> 
>> @Component(id = "payByInvoiceRadio", parameters = {
>> "value=literal:MANUAL_INVOICE",
>> 
>> "label=message:components.entities.EntitiesCreditCard.payByInvoice",
>> 
>> "fragment=manualInvoiceBlock"})
>> 
>> private Radio payByInvoiceRadio;
>> 
>> 
>>  @Component(id = "creditCardBlock", parameters = {
>> 
>> "visible=prop:showCreditCardBlock",
>> 
>> "alwaysSubmit=literal:false"})
>> 
>> private FormFragment creditCardBlock;
>> 
>> 
>> @Component(id = "manualInvoiceBlock", parameters = {
>> 
>> "visible=prop:showManualInvoiceBlock",
>> 
>> "alwaysSubmit=literal:false"})
>> 
>> private FormFragment manualInvoiceBlock;
>> 


Re: FormFragment validates on the server even when not visible

Posted by Yunhua Sang <yu...@gmail.com>.
I have the similar problem; I thinks it's because the FormFragment renders
a hidden element, when the zone gets refreshed, the hidden element's
disable property is set to be true, which is invalid, then the elements
within the FromFragment get submitted  I guess it's related to
isDeepVisible() Javascript function. Please correct me if I am wrong.

Probably you could specify the visibleBound property of the FormFragment,
to override the default behavior.





On Thu, Jul 11, 2013 at 7:16 AM, Joost Schouten (ml)
<jo...@jsportal.com>wrote:

> Hi,
>
> I'm using a FormFragment triggered by two Radio's in a RadioGroup. This all
> works fine and validation works as expected. The hidden Fragment is ignored
> when the form is submitted. Except for one situation:
>
> when I load the Form and containing FormFragment's in a Zone and use the
> visible attribute on the FormFragment to hide one of them due to a
> preselected Radio, the server will validate the fields in the Hidden
> FormFragment as well. If I select the Radio's back and forth it works as
> expected. When debugging I noticed the ProcessSubmission ComponentActions
> are executed where they are not when the formfragment is ignored as
> expected. Also the t:formdate is longer in my failing case as opposed to
> the scenario where it ignores my hidden fields. This leads me to believe
> there is some sort of javascript initialization call not being called in my
> failing case.
>
> Has anyone seen this before? And clues on how to solve it? I'm on Tap 5.3.6
>
> Thanks,
> Joost
>
> some of my code:
>
> @Component(id = "paymentTypeRadioGroup", parameters = {"value=paymentType",
>
>  "label=message:components.entities.EntitiesCreditCard.payByTypeLabel",
>
>  "validate=required"})
>
> private RadioGroup paymentTypeRadioGroup;
>
>
>   @Mixins("TriggerFragment")
>
> @Component(id = "payByCreditCardRadio", parameters = {
> "value=literal:CREDIT_CARD",
>
>  "label=message:components.entities.EntitiesCreditCard.payByCreditCard",
>
>  "fragment=creditCardBlock"})
>
> private Radio payByCreditCardRadio;
>
>
>  @Mixins("TriggerFragment")
>
> @Component(id = "payByInvoiceRadio", parameters = {
> "value=literal:MANUAL_INVOICE",
>
>  "label=message:components.entities.EntitiesCreditCard.payByInvoice",
>
>  "fragment=manualInvoiceBlock"})
>
> private Radio payByInvoiceRadio;
>
>
>   @Component(id = "creditCardBlock", parameters = {
>
>  "visible=prop:showCreditCardBlock",
>
>  "alwaysSubmit=literal:false"})
>
> private FormFragment creditCardBlock;
>
>
>  @Component(id = "manualInvoiceBlock", parameters = {
>
>  "visible=prop:showManualInvoiceBlock",
>
>  "alwaysSubmit=literal:false"})
>
> private FormFragment manualInvoiceBlock;
>

Re: FormFragment validates on the server even when not visible

Posted by "Joost Schouten (mailing lists)" <jo...@jsportal.com>.
A bit more on this. What seems to be going wrong that in my case the hidden form fields in the FormFragment's are submitted even when the fragments are hidden on initial render. When I show and hide them again, the hidden fields get a "disabled" attribute preventing them hidden from-fields from being submitted. It seems to me that this "disabled" attribute should also be provided on initial render if the fragment is hidden.

I now solved it by contributing some javascript to the ajax response disabling the hidden fields myself as shown in [1]. But I'm sure this is not how it is intended.

I'd love to feedback on this one. Thoughts?

Cheers,
Joost

[1] script in my event handler loading a Block containing the FormFragments and form elements.

ajaxResponseRenderer.addCallback(new JavaScriptCallback() {
	public void run(JavaScriptSupport javascriptSupport) {	            		
	        if (!isShowCreditCardBlock()) {
	            	javascriptSupport.addScript("$$('.creditCardFormItems.t-invisible INPUT[type=hidden]')[0].disabled=true;");
	        }

	        if (!isShowManualInvoiceBlock()) {
	        	javascriptSupport.addScript("$$('.manualInvoiceBlock.t-invisible INPUT[type=hidden]')[0].disabled=true;");
	       }
	}
});


On Jul 11, 2013, at 1:16 PM, Joost Schouten (ml) wrote:

> Hi,
> 
> I'm using a FormFragment triggered by two Radio's in a RadioGroup. This all
> works fine and validation works as expected. The hidden Fragment is ignored
> when the form is submitted. Except for one situation:
> 
> when I load the Form and containing FormFragment's in a Zone and use the
> visible attribute on the FormFragment to hide one of them due to a
> preselected Radio, the server will validate the fields in the Hidden
> FormFragment as well. If I select the Radio's back and forth it works as
> expected. When debugging I noticed the ProcessSubmission ComponentActions
> are executed where they are not when the formfragment is ignored as
> expected. Also the t:formdate is longer in my failing case as opposed to
> the scenario where it ignores my hidden fields. This leads me to believe
> there is some sort of javascript initialization call not being called in my
> failing case.
> 
> Has anyone seen this before? And clues on how to solve it? I'm on Tap 5.3.6
> 
> Thanks,
> Joost
> 
> some of my code:
> 
> @Component(id = "paymentTypeRadioGroup", parameters = {"value=paymentType",
> 
> "label=message:components.entities.EntitiesCreditCard.payByTypeLabel",
> 
> "validate=required"})
> 
> private RadioGroup paymentTypeRadioGroup;
> 
> 
>  @Mixins("TriggerFragment")
> 
> @Component(id = "payByCreditCardRadio", parameters = {
> "value=literal:CREDIT_CARD",
> 
> "label=message:components.entities.EntitiesCreditCard.payByCreditCard",
> 
> "fragment=creditCardBlock"})
> 
> private Radio payByCreditCardRadio;
> 
> 
> @Mixins("TriggerFragment")
> 
> @Component(id = "payByInvoiceRadio", parameters = {
> "value=literal:MANUAL_INVOICE",
> 
> "label=message:components.entities.EntitiesCreditCard.payByInvoice",
> 
> "fragment=manualInvoiceBlock"})
> 
> private Radio payByInvoiceRadio;
> 
> 
>  @Component(id = "creditCardBlock", parameters = {
> 
> "visible=prop:showCreditCardBlock",
> 
> "alwaysSubmit=literal:false"})
> 
> private FormFragment creditCardBlock;
> 
> 
> @Component(id = "manualInvoiceBlock", parameters = {
> 
> "visible=prop:showManualInvoiceBlock",
> 
> "alwaysSubmit=literal:false"})
> 
> private FormFragment manualInvoiceBlock;


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