This discussion is archived
9 Replies Latest reply: Dec 10, 2012 2:44 AM by Dipak R RSS

Item with autocomplete return id using jquery.

Dipak R Newbie
Currently Being Moderated
Hi,

I have created one emp_name text item using this link

http://dbswh.webhop.net/htmldb/f?p=BLOG:READ:0::::ARTICLE:1862200346659568

This will make a text item auto complete and return ID of text.

For example a table have "emp_name","emp_id" columns and if we type "emp_name" in text field then it will save "emp_id" of selected emp to new hidden field.

If i remove some text from emp_name text item and that name dose not exists in table then the hidden field have the "emp_id" of previously entered "emp_name" instead of null.
I just want to clear that hidden item if "emp_name" does not exists in the table.

please help me to come out this issue.
  • 1. Re: Item with autocomplete return id using jquery.
    VC Guru
    Currently Being Moderated
    What version of APEX are you on?

    If you are on 4.x try this Combobox plugin
  • 2. Re: Item with autocomplete return id using jquery.
    Dipak R Newbie
    Currently Being Moderated
    Hi VC,
    Thanks for reply...

    I am using apex 4.2.
    Your refer plugin have a bug in it..
    it is not populating row if table contain approx 50000 rows, it only searching for first 5000 rows i think.
    So, its not working properly...

    If you have this solution then it also work for me...

    Thanks....
  • 3. Re: Item with autocomplete return id using jquery.
    787577 Newbie
    Currently Being Moderated
    Hi

    I am using autcompletion based on [url http://dbswh.webhop.net/htmldb/f?p=BLOG:READ:0::::ARTICLE:1862200346659568]
    try this, this works for me in apex 4.1

    following code is executed when page loads $().ready()
              $searchItem = $( "#autocompleteId");
    
    
              $searchItem.live("blur", function(event) {
              
             var autocomplete = $(this).data("autocomplete");
             var matcher = new RegExp("^" + $.ui.autocomplete.escapeRegex($(this).val()) + "$", "i");
             var myInput = $(this);
             autocomplete.widget().children(".ui-menu-item").each(function() {
                 //Check if each autocomplete item is a case-insensitive match on the input
                 var item = $(this).data("item.autocomplete");
    
                 if (matcher.test(item.label || item.value || item)) {
                     //There was a match, lets stop checking
                     autocomplete.selectedItem = item;
                     return;
                 } 
                   
             });
             //if there was a match trigger the select event on that match
             //I would recommend matching the label to the input in the select event
              if ($(this).val() == '') {
              
                        $(this).val('');
                        $valueItem.val('');
                        
                   
              } else {
                   if (autocomplete.selectedItem) {
                        autocomplete._trigger("select", event, {
                             item: autocomplete.selectedItem
                        });
                   //there was no match, clear the input
                   } else {
                        $(this).val('');
                        $valueItem.val('');
                   }
              
              
              }
         });
    Edited by: Baki Sine on Dec 6, 2012 11:55 PM

    Edited by: Baki Sine on Dec 7, 2012 12:22 AM
  • 4. Re: Item with autocomplete return id using jquery.
    VC Guru
    Currently Being Moderated
    Dipak R wrote:
    Hi VC,
    Thanks for reply...

    I am using apex 4.2.
    Your refer plugin have a bug in it..
    it is not populating row if table contain approx 50000 rows, it only searching for first 5000 rows i think.
    So, its not working properly...

    If you have this solution then it also work for me...

    Thanks....
    Dipak,

    Why would you want to see 50000 records in a drop-down list and scroll through them??? Just think of using something like that yourself!

    It's not a bug and that is how it should work, because the plugin was restricted to show the first/matched 500 records. The idea of combobox is that you can actually type and filter the results so it will be easy to find.

    You can amend the plugin to increase the maximum rows parameter(which is currently set to 500)

    Thanks,
    Vikram
  • 5. Re: Item with autocomplete return id using jquery.
    Dipak R Newbie
    Currently Being Moderated
    Hi Vc,


    I don't want 50000 records, i just led select list to search in 50000 rows then it will work for me, bcoz my search string might not from 500 rows.
    If I amend the plugin to 50000 then takes lot page load time.

    Lets take example of this link

    http://apex.oracle.com/pls/apex/f?p=35538:1

    In report search for "sardar", it will return approx 74 rows.
    but in plugin if I search for "sardar" then no data found, had set a 500 rows in plugin parameters.
    If I change plugin parameters to 50000 rows then it work fine but take a lot of time to load page.


    To solve this issue we have found this solution, please click on "DbSWH" tab.
    This will return all records of "sardar" and fill the id in "id" textbox.
    But my concern is suppose I press backspace in text of textbox of search and remove some text and that text is not exists in then table, in this case we have no ID for this text in table if so then I want to clear ID textbox.

    Thank you very much for help.....
  • 6. Re: Item with autocomplete return id using jquery.
    VC Guru
    Currently Being Moderated
    Got you!!.. Since you have large amount of data I was expecting you to use the Combobox with LazyLoad set to Yes

    Could you please edit the combobox item on page 4 and amend the settings to use Lazy Load to Yes and test your above scenario

    Lazy Loading: If set to yes, the matching values will be read from the database each time the user types a character. If set to no, all values will be read only once when the page is rendered.
  • 7. Re: Item with autocomplete return id using jquery.
    Dipak R Newbie
    Currently Being Moderated
    Hi, VC

    Thanks a lot.....

    I have tried it, but it's take a lot of time to search ....
    Bcoz have a large number of rows in database... around 50,000

    Edited by: Dipak R on Dec 10, 2012 2:14 AM
  • 8. Re: Item with autocomplete return id using jquery.
    VC Guru
    Currently Being Moderated
    Explain plan on your SQL and create indexes where appropriate
  • 9. Re: Item with autocomplete return id using jquery.
    Dipak R Newbie
    Currently Being Moderated
    Hi VC,

    Yes it's seems fine...

    Would you please help me to solve "*DbSWH*"(http://apex.oracle.com/pls/apex/f?p=35538:) tab page autocomplete field.

    I want to clear the item "Id" if the search string does not exists(means if i select one item from search then Id filled, then If remove some text from search then that text does not exist in the table so the Id field must be null at that time).

    If I have this solution then it will be best for me.

    Thanks....

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points