6 Replies Latest reply on Mar 13, 2015 11:25 AM by edilmar

    New bug in RF 4.5.3 autocomplete

    edilmar

      I have an event in my autocomplete components to allow user to type a code or a description for a "field" (for example CITIES database table with CODCITY,DESCRIPTION).

      If user types code number "876", the component locates and shows the CITY with CODCITY=876.

      If user types description "CAMPO GRANDE", the component locates and shows the CITY with DESCRIPTION like "CAMPO GRANDE%".

      Until RF 4.5.2 (since 3.x versions), this works fine. Look below the form:

      RF-autocomplete452.jpg

      The JSF for autocomplete is this (I use minChars=100 to just do the search in the database after user types ENTER):

      <a4j:region id="a4j_ProprietarioFil_cidade">

        <a title="Digite uma descrição ou um código com no mínimo 5 caracteres.">

        <rich:autocomplete id="ProprietarioFil_cidade" value="#{proprietarioFil.entity.cidade}"

                           mode="cachedAjax" minChars="100" showButton="true" autofill="false"

                           autocompleteMethod="#{proprietarioFil.cidadeLookup}"

                           onkeypress="return enterToAutoComplete('formproprietarioFil:ProprietarioFil_cidade', 5, event);"

                           >

                           <f:converter converterId="cidadeConverter"/>

        </rich:autocomplete>

        </a>

      </a4j:region>

      The code for enterTuAutoComplete Javascript function is:

      function enterToAutoComplete(objName, minChars, evtKeyPress) {

        var input = getComponent(objName);

        var nTecla = evtKeyPress.keyCode;

        var autocomplete = input.rf.component;

        if (nTecla == 13) {

          var codigo = Number(input.value);

          if (codigo != NaN)

            minChars = 1;

          autocomplete.options.minChars = minChars;

          autocomplete.isFirstAjax = true;

          autocomplete.__updateState(evtKeyPress);

          autocomplete.options.minChars = 100;

          return false;

        }

        else

          return true;

      }

       

      I tried to debug the code in Chrome and both 4.5.2 and 4.5.3 appears to do the same things.

        • 1. Re: New bug in RF 4.5.3 autocomplete
          michpetrov

          You haven't explained what the bug is. In any case the change to autocomplete in 4.5.3 was RF-10964. "minChars" is the value of how many characters the user has to type in before the search is executed, but suggestions shouldn't be accepted if the number wasn't reached (that was the fix to the issue). You probably need to set minChars to the length of the typed value.

          • 2. Re: New bug in RF 4.5.3 autocomplete
            edilmar

            In 4.5.3 when I type a code or description and ENTER, the autocomplete do nothing.

            I think when you change the RF code to refactory the problem in [RF-10964] autocomplete delete key behavior creates inconsistent state - JBoss Issue Tracker

            my kind of control using ENTER to run the search stopped to work.

            And after I changed my code like your suggestion:

                   autocomplete.options.minChars = input.value.length;

            my interface became worst, because I use ENTER like a shortcut to filter button for all the components.

            Then, when I am into an autocomplete and press ENTER, the code to search autocomplete runs but the code to filter button runs too after.

            In versions <= 4.5.2, when I am into an autocomplete and press ENTER, just the code to search autocomplete runs.

            • 3. Re: New bug in RF 4.5.3 autocomplete
              edilmar

              If I change the default minChars to 5 in component, it works fine with normal behaviour that doesn't need to press ENTER.

              But this is a big problem because when the user types a CODE, not a DESCRIPTION, I want that CODE=1 works, not CODE=00001, that is a bad interface behaviour.

               

              I implemented this code in 2011, when I submitted this message in this forum: RF4 rich:autoComplete with ENTER to start search

              • 4. Re: New bug in RF 4.5.3 autocomplete
                michpetrov

                If you look at Autocomplete.js there is a "ajaxSuccess" function, all the fix did was changing

                 

                updateItemsList.call(_this, _this.value, event.componentData && event.componentData[_this.id]);
                

                to

                if (_this.options.minChars <= _this.value.length) {
                    updateItemsList.call(_this, _this.value, event.componentData && event.componentData[_this.id]);
                }
                

                 

                you need to make sure the check passes. If there are additional methods being executed then I assume there's another error in your code.

                • 5. Re: New bug in RF 4.5.3 autocomplete
                  edilmar

                  I think this changing was the cause of my problem because I use minChars=100 to start the search just when the user press ENTER, not when the user press minChars characters. The "if" above is a big problem for me. I am thinking about what to do to solve my problem.

                  • 6. Re: New bug in RF 4.5.3 autocomplete
                    edilmar

                    Hi,

                     

                    I solved the problem creating an oncomplete call:

                    <h:outputText styleClass="fontDefLabels" value="Search city:"/><br/>

                    <rich:autocomplete id="cidade" value="#{t.cidadeAtual}"

                          mode="cachedAjax" minChars="100" showButton="true" autofill="false"

                          autocompleteMethod="#{t.cidadeLookup}"

                          onkeypress="return enterToAutoComplete('formCad:cidade', 3, event);"

                          oncomplete="return afterEnterToAutoComplete('formCad:cidade');"

                          >

                      <f:converter converterId="cidadeConverter"/>

                    </rich:autocomplete>

                     

                     

                    and these are my JS functions:

                    function enterToAutoComplete(objName, minChars, evtKeyPress) {

                      if (isEnter(evtKeyPress)) {

                        var input = getComponent(objName);

                        var autocomplete = input.rf.component;

                        var codigo = Number(autocomplete.value);

                        if (!isNaN(codigo))

                          minChars = 1;

                        autocomplete.options.minChars = minChars;

                        autocomplete.isFirstAjax = true;

                        autocomplete.__updateState(evtKeyPress);

                        return false;

                      }

                      else

                        return true;

                    }

                    function afterEnterToAutoComplete(objName) {

                      var input = getComponent(objName);

                      var autocomplete = input.rf.component;

                      autocomplete.options.minChars = 100;

                      return true;

                    }

                    It would be nice Michal if next versions of rich:autocomplete have a new property something like "hotkey=XXX" and if I'd configure minChars="5" and hotkey="13", both conditions would be used to start the suggestions.