Skip to content

Commit

Permalink
refactor: use global JS for keyboard trigger of search in my tasks view
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Sendler committed Feb 6, 2025
1 parent e2c56ad commit fa546aa
Showing 1 changed file with 2 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
pt:aria-label="search"
styleClass="form-control searchfield"
value="#{Form.filter}"
onkeypress="submitSearch(event)"
onkeypress="submitOnEnter(event)"
>
<f:passThroughAttribute name="placeholder" value="#{label}" />
<c:if test="#{Form.filter ne ''}">
Expand All @@ -106,7 +106,7 @@
type="submit"
jsf:id="FilterAlle2"
jsf:forceId="true"
class="btn btn-blank"
class="btn btn-blank submitOnEnter"
jsf:action="#{Form.FilterAlleStart}" >
<span>
#{msgs.search}
Expand All @@ -116,21 +116,5 @@
<x:commandButton type="submit" id="FilterAlle" forceId="true" style="display: none;" action="#{Form.FilterAlleStart}" />
</div>

<script>
/** Submit the search on pressing Enter inside the search form.
* This is a workaround: A form element cannot be used, because
* we would end up with nested form elements, which is not allowed:
* https://stackoverflow.com/questions/379610/can-you-nest-html-forms
* The current outer form element is `:searchForm`
*/
function submitSearch(e) {
if(e.key != 'Enter') return
e.preventDefault()
var submit = document.querySelector('[id$="FilterAlle2"]');
submit.click()
}
</script>


</composite:implementation>
</ui:composition>

0 comments on commit fa546aa

Please sign in to comment.