Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

submit on enter

Avatar

Level 3

Is there an event for a field so that they can click the "enter" key and have the form submitted?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

You can test the xfa.event.commitKey on the exit event of the field. It will return a value of 2 if the user hit enter or a value of 3 if they hit tab.

Paul

View solution in original post

10 Replies

Avatar

Former Community Member

Sure ...a button field exhibits that behaviour.

Paul

Avatar

Level 4

Paul, that's not what I'm talking about... The first part of our form is

a search interface - so a user can enter a last name and hit the enter key

- and if so, I want the search to be executed. Right now they havce to

click a button to execute the search. I'd also like the enter key to

simulate the same thing. Any suggestions?

Avatar

Former Community Member

By default the enter key will give you a new line on a multi-line field. If you are in a single line field the enter key will exit the field, so you could execute your code on the exit event of the field.

Paul

Avatar

Level 4

Interesting, thanks. - the field is a single line text field. Tabbing

out of the field takes me to the next field, but hitting the enter key

makes the cursor go away and does not position to the next field. Although

the exit event is still fired. Cool for now, thanks.

Avatar

Level 4

Actually, I cannot execute my code on the exit event of the field, because

a user should be able to tab out of the field without executing the code,

but should be able to "enter" within the field to execute. Both the tab

and the enter execute the exit event. So the exit event won't work in

this case.... I wonder if I can check on the exit event whether they hit

the tab key or the enter key?

thanks

Avatar

Correct answer by
Former Community Member

You can test the xfa.event.commitKey on the exit event of the field. It will return a value of 2 if the user hit enter or a value of 3 if they hit tab.

Paul

Avatar

Level 10

Could you not also check for no data in the field and not execute the search if nothing is entered?

Avatar

Level 4

not really ,because they will be entering data. For example, they can

enter a last name, then tab to the zip code field, enter data, and hit

enter (at which point the search should execute based off the contents of

the last name and zip code fields), or, more simply, they may just want to

enter a last name and hit enter, and not further refine by zip code.

That's just one of three different search methods we are offering.

thanks,

elaine

Avatar

Former Community Member

Is the commitKey approach not acceptable?

Paul

Avatar

Level 4

It most certainly is, Paul. I was just answering Jono's question.

Thanks,

Elaine

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] ----