i need to do an ajax request when i click "enter" in inputText field, without refresh page. That's my code:
<h:form id="form-test">
<p:growl id="messages" showDetail="true"/>
<p:inputText id="inputEnter"
onkeypress="if (event.keyCode == 13) {onchange(); return false; }"
value="#{bean.content}">
<f:ajax event="change" listener="#{bean.save}" update="messages"/>
</p:inputText>
</h:form>
And in bean I have a simple method:
public void save(AjaxBehaviorEvent event){
...
}
All works, but It refresh page !!! Why ? How can I solve it ?
There is already a thread with a question somehow like yours How to handle the ENTER keypressed to trigger an onBlur() event?
I would just change
onkeypress="if (event.keyCode == 13) {e.preventDefault();
inputEnter.onchange(); return false; }"
If you use JQuery
$('#form-test\\:inputEnter').onchange();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With