OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to open a p:autoComplete suggestion list on focus

  • Thread starter Thread starter Jasper de Vries
  • Start date Start date
J

Jasper de Vries

Guest
I have an AutoComplete component which uses a dropdown button. I don't like that suggestions are only shown when I click the dropdown button (or start typing). I would like to show the suggestions on focus of the input component. So I tried this, but it doesn't work:

Code:
<p:autoComplete widgetVar="myAutoComplete"
                dropdown="true"
                onfocus="PF('myAutoComplete').dropdown.trigger('mouseup')"
                ...>

In the component listener it triggers a focus on the input, so it's causing a loop:

https://github.com/primefaces/prime...efaces/autocomplete/autocomplete.js#L374-L378

Code:
this.dropdown.on("mouseup", function() {
    if ($this.active) {
        $this.searchWithDropdown();
        $this.input.trigger('focus');
    }
}

I couldn't find an other way to do it. Is there a way to do this without monkey patching the component?

I'm on PrimeFaces 12.

<p>I have an <code>AutoComplete</code> component which uses a dropdown button. I don't like that suggestions are only shown when I click the dropdown button (or start typing). I would like to show the suggestions on focus of the input component. So I tried this, but it doesn't work:</p>
<pre class="lang-html prettyprint-override"><code><p:autoComplete widgetVar="myAutoComplete"
dropdown="true"
onfocus="PF('myAutoComplete').dropdown.trigger('mouseup')"
...>
</code></pre>
<p>In the component listener it triggers a focus on the input, so it's causing a loop:</p>
<p><a href="https://github.com/primefaces/prime...efaces/autocomplete/autocomplete.js#L374-L378" rel="nofollow noreferrer">https://github.com/primefaces/prime...efaces/autocomplete/autocomplete.js#L374-L378</a></p>
<pre class="lang-js prettyprint-override"><code>this.dropdown.on("mouseup", function() {
if ($this.active) {
$this.searchWithDropdown();
$this.input.trigger('focus');
}
}
</code></pre>
<p>I couldn't find an other way to do it. Is there a way to do this without monkey patching the component?</p>
<p>I'm on PrimeFaces 12.</p>
 

Latest posts

M
Replies
0
Views
1
Meliodas Dragon
M
Top