<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JQuery UI &#8211; Jitendra Zaa</title>
	<atom:link href="https://www.jitendrazaa.com/blog/tag/jquery-ui/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.jitendrazaa.com/blog</link>
	<description>AI, Salesforce, ServiceNow &#38; Enterprise Tech Guides</description>
	<lastBuildDate>Wed, 02 Apr 2014 08:56:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
<site xmlns="com-wordpress:feed-additions:1">87744916</site><atom:link rel="search" type="application/opensearchdescription+xml" title="Search Jitendra Zaa" href="https://www.jitendrazaa.com/blog/wp-json/opensearch/1.1/document" />	<item>
		<title>AutoComplete Component in Visualforce using JQueryUI</title>
		<link>https://www.jitendrazaa.com/blog/salesforce/ajax-based-autocomplete-component-in-salesforce-using-jquery-ui-and-json/</link>
					<comments>https://www.jitendrazaa.com/blog/salesforce/ajax-based-autocomplete-component-in-salesforce-using-jquery-ui-and-json/#comments</comments>
		
		<dc:creator><![CDATA[Jitendra]]></dc:creator>
		<pubDate>Fri, 28 Jun 2013 18:23:42 +0000</pubDate>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Salesforce]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[Apex]]></category>
		<category><![CDATA[Autocomplete]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JQuery UI]]></category>
		<category><![CDATA[JSON]]></category>
		<guid isPermaLink="false">http://JitendraZaa.com/blog/?p=3347</guid>

					<description><![CDATA[In this tutorial, I am going to explain very Simple AJAX and JSON based Auto Complete component with the help of JQuery UI. First I am assuming that you already have Static Resource of named &#8220;AutoCompleteWithModal&#8220;. This Static resource has all images, CSS and JQuery library needed to implement this component. In one of my [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>In this tutorial, I am going to explain very Simple AJAX and JSON based Auto Complete component with the help of <a title="jQuery UI" href="http://jqueryui.com/" target="_blank" rel="nofollow">JQuery UI</a>. First I am assuming that you already have Static Resource of named &#8220;<a title="Salesforce Static Resource" href="https://jitendrazaa.com/blog/wp-content/uploads/2013/06/AutoCompleteWithModal.zip" target="_blank">AutoCompleteWithModal</a>&#8220;. This Static resource has all images, CSS and JQuery library needed to implement this component.</p>
<p>In <a title="JSON Output in Visualforce" href="https://jitendrazaa.com/blog/salesforce/json-output-in-visualforce/" target="_blank">one of my old post</a>, I have already explained that how to generate JSON in Visualforce page. So Considering same article I have create Visualforce page named &#8220;Account_JSON&#8221; which returns list of Accounts on basis of text entered in input field.<span id="more-3347"></span></p>
<p><strong>Live Demo :</strong></p>
<p>try searching &#8220;gen&#8221; or &#8220;edg&#8221; and spacebar, It will load account after one space.</p>
<p><iframe src="http://shivasoft-developer-edition.ap1.force.com/Exp/AutoCompleteDemo" height="100" width="100%" frameborder="0" scrolling="no"></iframe></p>
<p><strong>Visualforce Account_JSON :</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;apex:page Controller=&quot;AccountJSONCreator&quot; contentType=&quot;application/x-JavaScript; charset=utf-8&quot; showHeader=&quot;false&quot; standardStylesheets=&quot;false&quot; sidebar=&quot;false&quot;&gt;
{!JSON}
&lt;/apex:page&gt;
</pre>
<p><strong>Controller AccountJSONCreator :</strong></p>
<pre class="brush: java; title: ; notranslate">
public with sharing class AccountJSONCreator {

    public String getJSON()
    {
        String AccountName = Apexpages.currentPage().getParameters().get('AccName');
        List&lt;AccountWrapper&gt; wrp = new List&lt;AccountWrapper&gt;();
        for (Account a : &#x5B;Select a.Id, a.Website, a.Name, a.BillingCountry, a.BillingCity
                            From
                                Account a
                            WHERE Name Like : '%'+AccountName+'%' ]) {
               AccountWrapper w = new AccountWrapper (a.Name, nullToBlank (a.BillingCountry), nullToBlank (a.BillingCity));
               wrp.add(w);
            }
        return JSON.serialize(wrp);
    }

    public String nullToBlank(String val)
    {
        return val == null ?'':val;
    }

    public class AccountWrapper
    {
        String AccName,BillingCountry,BillingCity;

        public AccountWrapper(String aName, String bCountry, String bCity)
        {
            AccName = aName;
            BillingCountry = bCountry;
            BillingCity = bCity;
        }
    }

    static testMethod void AccountJSONCreatorTest() {
        AccountJSONCreator obj = new AccountJSONCreator();
        obj.getJSON();
    }
}
</pre>
<p>Now let&#8217;s create a Component which will make AJAX request to above visualforce page &#8220;Account_JSON&#8221; and Parse JSON page using JQuery.</p>
<p><strong>Component Autocomplete_Component :</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;apex:component&gt;
 &lt;apex:attribute name=&quot;ComponentLabel&quot; description=&quot;Label of Component&quot;
                    type=&quot;String&quot; required=&quot;true&quot;/&gt;

&lt;apex:stylesheet value=&quot;{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryUI/css/ui-lightness/jquery-ui-1.8.17.custom.css')}&quot;/&gt;
&lt;apex:includeScript value=&quot;{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryUI/js/jquery-1.7.1.min.js')}&quot;/&gt;
&lt;apex:includeScript value=&quot;{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryUI/js/jquery-ui-1.8.17.custom.min.js')}&quot;/&gt;
&lt;apex:stylesheet value=&quot;{!URLFOR($Resource.AutoCompleteWithModal, '/JQueryModal/css/basic.css')}&quot;/&gt;

&lt;style type=&quot;text/css&quot;&gt;
    .ui-autocomplete-loading { background: white url('{!URLFOR($Resource.AutoCompleteWithModal, 'AjaxLoad.gif')}') right center no-repeat; }
&lt;/style&gt;

{!ComponentLabel} &lt;apex:inputText id=&quot;theTextInput&quot;/&gt;

&lt;script type=&quot;text/javascript&quot;&gt;
//$ac - AutoComplete

$ac = jQuery.noConflict();

function getLoadingImage()
{
    var loadImagURL = &quot;{!URLFOR($Resource.AutoCompleteWithModal, 'BigLoad.gif')}&quot;;
    var retStr = &#x5B;'&lt;img src=&quot;', loadImagURL ,'&quot; title=&quot;loading...&quot; alt=&quot;loading...&quot; class=&quot;middleAlign&quot; /&gt;'];
    return retStr.join(&quot;&quot;);
}

var sourcePage = 'https://c.ap1.visual.force.com/apex/Account_JSON?core.apexpages.devmode.url=0';

 $ac(function() {
        var txtVal =  $ac('&#x5B;id=&quot;{!$Component.theTextInput}&quot;]');
        //This method returns the last character of String
        function extractLast(term) {
            return term.substr(term.length - 1);
        }

        $ac('&#x5B;id=&quot;{!$Component.theTextInput}&quot;]').autocomplete({
            source: function( request, response ) {

                //Abort Ajax
                var $this = $ac(this);
                var $element = $ac(this.element);
                var jqXHR = $element.data('jqXHR');
                if(jqXHR)
                    jqXHR.abort();

                $ac('&#x5B;id=&quot;{!$Component.theTextInput}&quot;]').addClass('ui-autocomplete-loading');
                //prompt('',sourcePage+'&amp;key='+txtVal.val());
                $element.data('jqXHR',$ac.ajax({
                    url: sourcePage+'&amp;AccName='+txtVal.val(),
                    dataType: &quot;json&quot;,
                    data: {
                    },
                    success: function( data ) {
                        response( $ac.map( data , function( item ) {
                            return {
                                label: '&lt;a&gt;'+
                                item.AccName+&quot;&lt;br /&gt;&quot;+
                                '&lt;span style=&quot;font-size:0.8em;font-style:italic&quot;&gt;'
                                +item.BillingCity+', '+item.BillingCountry+
                                &quot;&lt;/span&gt;&lt;/a&gt;&quot;,
                                value: item.AccName
                            }
                        }));
                    },
                    complete: function() {

                        //This method is called either request completed or not
                        $this.removeData('jqXHR');

                        //remove the class responsible for loading image
                        $ac('&#x5B;id=&quot;{!$Component.theTextInput}&quot;]').removeClass('ui-autocomplete-loading');
                    }
                })
                );

            },
            search: function() {
                /*
                // If last character is space
                    var term = extractLast(this.value);
                    if(term == &quot; &quot;)
                    {
                        return true;
                    }
                */

                //If String contains at least 1 space
                if (this.value.indexOf(&quot; &quot;) &gt;= 0)
                {
                    $ac('&#x5B;id=&quot;{!$Component.theTextInput}&quot;]').autocomplete('option', 'delay', 500);
                    return true;
                }
                return false;
            },
            focus: function() {
                // prevent value inserted on focus
                return false;
            },
            select: function(event, ui) {
                var selectedObj = ui.item;
                //alert(selectedObj.compId);
                //getCompanyDetail(selectedObj.compId);
                return true;
            }
        }).data(&quot;autocomplete&quot;)._renderItem = autoCompleteRender;

    });

function autoCompleteRender(ul, item) {
    return $ac(&quot;&lt;li&gt;&lt;/li&gt;&quot;).data(&quot;item.autocomplete&quot;, item).append(item.label).appendTo(ul);
}

&lt;/script&gt;
&lt;/apex:component&gt;
</pre>
<p>Now Visualforce page, which will host above Component.</p>
<p><strong>Viusalforce Page : AutoCompleteDemo</strong></p>
<pre class="brush: xml; title: ; notranslate">
&lt;apex:page &gt;
    &lt;apex:form &gt;
        &lt;c:autocomplete_component ComponentLabel=&quot;Enter Account Name : &quot;/&gt;
    &lt;/apex:form&gt;
&lt;/apex:page&gt;
</pre>
<figure id="attachment_3350" aria-describedby="caption-attachment-3350" style="width: 599px" class="wp-caption aligncenter"><a href="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2013/06/JQuery-UI-and-JSON-based-AJAX-AutoComplete-Component-in-Salesforce.png?ssl=1"><img data-recalc-dims="1" fetchpriority="high" decoding="async" class="size-full wp-image-3350" alt="JQuery UI and JSON based AJAX AutoComplete Component in Salesforce" src="https://i0.wp.com/jitendrazaa.com/blog/wp-content/uploads/2013/06/JQuery-UI-and-JSON-based-AJAX-AutoComplete-Component-in-Salesforce.png?resize=599%2C407&#038;ssl=1" width="599" height="407" /></a><figcaption id="caption-attachment-3350" class="wp-caption-text">JQuery UI and JSON based AJAX AutoComplete Component in Salesforce</figcaption></figure>
<p>Download Static resource &#8211; <a href="https://www.jitendrazaa.com/blog/wp-content/uploads/2013/06/AutoCompleteWithModal1.zip">AutoCompleteWithModal</a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.jitendrazaa.com/blog/salesforce/ajax-based-autocomplete-component-in-salesforce-using-jquery-ui-and-json/feed/</wfw:commentRss>
			<slash:comments>19</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">3347</post-id>	</item>
	</channel>
</rss>

<!--
Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/?utm_source=w3tc&utm_medium=footer_comment&utm_campaign=free_plugin

Page Caching using Disk: Enhanced 
Minified using Disk

Served from: www.jitendrazaa.com @ 2026-06-24 07:37:42 by W3 Total Cache
-->