0

I have a form built with FORM Api. It has a text field, with Autocomplete. I also have another form, with several fields, some of them with Autocomplete.

It works well, but I have to press Enter Key twice to send the form.

The first Enter key is to select an item. The second Enter key sends the selected item for process.

The behaviour that I have seen outside, in the wild, and which is customary in thousands of millions of sites is this:

  1. If only one field form (search form, for example), once you click or press enter with the suggested term highlighted, the form will be sent (let's call this behaviour One-Clik). Note: there are no multiple selections option, if not, this behaviour would have to be different.
  2. In several fields form, you just select and press ENTER, and can continue filling other fields. If you want to submit the form, you press the Go button or just click Enter in the autocomplete field if that is the last one you used. This is called Two-Clicks, except that: you can write some words in the autosuggest field, and not choose anything. The desired behaviour would be that just clicking ONCE the Enter key, you would submit the form. So this behaviour is really One-Click, with the only exception that selecting an item by pressing Enter key does not qualify as a click.

In order to have it working, I had to rewrite the autocomplete.js. Is there another solution?

I cannot understand how Drupal cannot manage by default such an easy behaviour, seem in millions of sites. And I can assure that for normal users this is very frustrating and irritating and very counterintuitive.

  • Yep that's how it's written, and yep you'll need to replace/augment that yourself if you want different features (just like anything). Personally I agree with requiring two return presses to submit the form. More intuitive in my opinion, and will produce fewer problems for mobile users. – Clive Jan 4 '16 at 9:15
  • Google does not require two return presses. Most of my users criticize and say that it is not intuitive. At least there could be some flexibility with some config screen and two slightly versions of the code (it does not require too much re-coding). My 2-cents thought, anyway. – Cesar Jan 4 '16 at 9:24
  • Yeah just a matter of opinion really @Cesar. jQuery UI autocomplete requires two button presses, for example, and that's used a lot more widely than Google's. Left-brain/right-brain thing probably – Clive Jan 4 '16 at 9:27
  • Ok. It is simply that my boss and client are very demanding on lots of things that should behave like they want because they have seen elsewhere. I try to say that Drupal is extremely customizable but some behaviours are less customizables than other, but it seems they won't listen to me. – Cesar Jan 4 '16 at 15:23
1

I think this is a JQuery problem rather than a Drupal problem.

You should be able to add a JavaScript function, something like the following:

$("#searchField").select(function(event, ui) { 
    $("#searchField").val(ui.item.label);
    $("#searchForm").submit(); 
});

It's necessary to assign the value before submitting the form because if the user clicked on a list entry with the mouse, the value won't have been assigned before the select event occurs.

I haven't actually tested this, but hopefully this will send you in the right direction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.