0

my form consists of following elements:

  1. icefaces text field to enter search criteria.
  2. icefaces command button (find) to make partial submit and populate a div with new list of matched users.
  3. other two icefaces text fields, when submitting whole form i need their values.

Requirement: i want when user press enter in the text input field, that find button gets clicked (when the button gets clicked by mouse it makes partial submit automatically)

so here's what i tried:

<ice:inputText id="recipient" value="#{myBean.searchValue}" size="60" 
                     onkeydown="handleEnter(event,this.form);" >
                </ice:inputText>

                <ice:commandButton id="find" value="Find"  action="#{myBean.findEmployees}" partialSubmit="true"
                     >
                    <f:ajax execute="@this" render="employees" />
                </ice:commandButton> 
  • the JS method:

    function handleEnter(event,form){
    
       if (event.keyCode == 13){
        document.getElementById(form.name+':find').click(); 
       }
    }
    
  • the generated ice command button:

     <input type="submit" value="Find" style="width: 60px;"     onfocus="setFocus(this.id);"     onclick="iceSubmitPartial(form, this, event);return false;" onblur="setFocus('');" name="myForm:find" id="myForm:find" class="iceCmdBtn findButton">
    

ISSUE: what happens is the when user press enter, find button is invoked, but whole form gets submitted, so a required validation error appears for the other two text fields.

please advise why whole form is getting submitted, and how to handle such issue.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
  • I'm not sure what HTML exactly an `` generates, but try `onclick()` instead of `click()`. It will then only fire the button's `onclick` function instead of virtually clicking the button. – BalusC Jan 04 '12 at 17:50
  • @BalusC, onclick gives same behavior, i added generated code of ice command button. – Mahmoud Saleh Jan 05 '12 at 12:31

2 Answers2

0

to get the enter button working fine with partial submit, i have to remove the 'required=true' tag from the inputs and make the validation with JS.

Mahmoud Saleh
  • 33,303
  • 119
  • 337
  • 498
-1

set immediate = true on the button

Paul
  • 1