Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Hide submit button when there's nothing to submit

Avatar

Former Community Member

Hi,

I have a simple order form with a 'running total' of quantities ordered at the top of the form, calculated thus (FormCalc):

 

$ = sum(Products.PRODUCT_GROUPS.DATA[*].PRODUCTS.DATA[*].Quantity)

If this quantity is zero (i.e. nothing has been ordered) then I want to prohibit the form being submitted by email. I thought the best way of doing this would be to hide the submit button when this field is zero, and show it when > 0.

I tries appending this code to the same calculate event of this field:

if ( $ > 0 )  then   

    Button1.presence= "visible"

else

    Button1.presence= "hidden"

endif

but no go.

Sorry if this is real simple, but I'd appreciate help!

Thanks.

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

When in the code window, you'll see it says something about Ctrl+Click for SOM expression. So if in the event code for one item, you can press Control then click on another item and it will insert the correct reference to it in your code. You have to make sure the focus is in your code when you do it and the mouse cursor will turn into a wide V.

You can right click in the code window and select Check Script Syntax to see if there are any problems.

When viewing the form in Preview, Ctrl+J brings up the JavaScript debugger. It may first need some config in Acrobat. It has been a while since I set that up. Instead of doing app.alert, you can do console.println and it will write to the JavaScript console. Occasionally, you may need to debug something dealing with focus and the app.alert itself affects the focus.

Have you thought about putting your code in a preSubmit event and displaying a message that nothing has been entered? Also do xfa.event.cancelAction = true

View solution in original post

4 Replies

Avatar

Former Community Member

if ( $.rawValue > 0 )  then  

    Button1.presence= "visible"

else

    Button1.presence= "hidden"

endif

Except you probably don't want it in the calculate event. Maybe the change or exit event.

In change:

if (xfa.event.newText > 0 )  then  

    Button1.presence= "visible"

else

    Button1.presence= "hidden"

endif

Avatar

Former Community Member

Thanks for replying, Steve.

Change event doesn't get called (I put messagebox displays all over the place!), I guess because there is no user input - it's a read only calculate field.

Layout:ready, form:ready and a few others were called so I tried the formcalc code in those but no good.

Tried creating a new text field just so I could use its events, including calculate, changed $.rawValue to TotalQty.rawValue but no good.

This isn't critical, just a nice to have, but I'm really keen to understand better how things hang together. A couple of books

I've seen recommended are winging their way to me now.

Button1 and TotalQty fields are at the same level of the hieerarchy so I think my referencing is OK. 

Cheers.

Nigel.

Avatar

Correct answer by
Former Community Member

When in the code window, you'll see it says something about Ctrl+Click for SOM expression. So if in the event code for one item, you can press Control then click on another item and it will insert the correct reference to it in your code. You have to make sure the focus is in your code when you do it and the mouse cursor will turn into a wide V.

You can right click in the code window and select Check Script Syntax to see if there are any problems.

When viewing the form in Preview, Ctrl+J brings up the JavaScript debugger. It may first need some config in Acrobat. It has been a while since I set that up. Instead of doing app.alert, you can do console.println and it will write to the JavaScript console. Occasionally, you may need to debug something dealing with focus and the app.alert itself affects the focus.

Have you thought about putting your code in a preSubmit event and displaying a message that nothing has been entered? Also do xfa.event.cancelAction = true

Avatar

Former Community Member

Thanks for your time, Steve.

Your preSubmit suggestion works a treat and I'm going to go with that rather than spend any more time on hiding the submit button.

Cheers.

Nigel.

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----