0

I have develop jquery json autoxcomplete search there i want to terminate spaces when results coming . Currently when i search somthing placecing space infront it wont give any results. Please advice me how to add thsi option working

    jQuery.extend( jQuery.ui.autocomplete.prototype, {
              _renderItem: function( ul, item ) {
                  var term = this.element.val(),
                      regex = new RegExp( '(' + term + ')', 'gi' );
                  html = item.label.replace( regex , "<b>$&</b>" );
                  return jQuery( "<li></li>" )
                      .data( "item.autocomplete", item )
                      .append( jQuery("<a></a>").html(html) )
                      .appendTo( ul );
              }
          });


             jQuery.noConflict();
             jQuery(function(){
                 jQuery("#searchr").autocomplete({
                     source:'<?php echo JURI::root().'modules/mod_jomdirectory_search/tmpl/religious.php'; ?>',

                     minLength:1
                 });
             });
fdz
  • 73
  • 2
  • 22
  • 2
    http://stackoverflow.com/questions/498970/how-do-i-trim-a-string-in-javascript – Colandus Feb 25 '14 at 17:19
  • @Colandus : thanks , btw how to trim middle spaces like if a word is "temple" when someone search "tem ple" stil the autocomplete works . please advice – fdz Feb 25 '14 at 17:23
  • @s_fdo this should do that http://stackoverflow.com/questions/6623231/remove-all-white-spaces-from-text – RossG Feb 25 '14 at 17:34
  • @RossG : thanks i gone thru that , is it possible to put that here html = item.label.replace( regex , "$&" ); i mean this part ".replace(/ /g,'')" – fdz Feb 25 '14 at 17:41

1 Answers1

0

Take a look at the 'trim' function...

https://api.jquery.com/jQuery.trim/

http://jsfiddle.net/3s75T/

$('input').on('blur', function() {
  term = $.trim($(this).val());
  alert( term ); 
});
superUntitled
  • 22,351
  • 30
  • 83
  • 110
  • :thanks , btw , is this possible to make escape spaces when searching as well , if the word is "abc efg" if person type it as "abcefg" also autocomplete populate the result ? please advice – fdz Feb 25 '14 at 17:30
  • yes, http://stackoverflow.com/questions/14236873/disable-spaces-in-input-and-allow-back-arrow – superUntitled Mar 06 '14 at 21:05