Showing posts with label JqueryUI. Show all posts
Showing posts with label JqueryUI. Show all posts

Thursday, May 9, 2013


[Live Demo]

This is another blog regarding so called Easy Jquery Component.Now this component helps you to generate  the Jquery Tabs very easily in a Visualforce pages. Follows the same syntax as the standard component, with added Jquery goodness. Pretty straight forward and can include standard components inside the Jquery tabs.

How it looks like ?



How to use the components?

  • <c:Tabpanel> : A wrapper component that holds all the tab together inside a panel.
  • <c:Tab> : Represents a single Tab inside a tabpanel.
Below is a sample code to generate a Jquery Tab

<!--Tab Panel -->  
   <c:Tabpanel >  
     <!--First Tab-->  
     <c:Tab title="Tab 1">  
       This is a tab 1. You can add standard component inside also.  
       <apex:pageBlock title="Standard page block">  
         This is a pageblock component.  
         <br/>  
         <apex:pageBlockSection title="This is a section" collapsible="false">  
         </apex:pageBlockSection>  
       </apex:pageBlock>  
     </c:Tab>  
     <!--Second Tab -->  
     <c:Tab title="Tab 2">  
       This is a tab 2  
     </c:Tab>  
   </c:Tabpanel>  

Codebase


Tuesday, April 23, 2013


[Live Demo]

[Updated To 1.1]

Well while working with Visualforce pages, you will feel like the UI is kinda old and not that catchy. But believe me VF is not that bad at all!  You just need to add the right ingredients.

And guess what the most stable js library JQUERY and JQUERY UI mixes very well with Visualforce pages, to give awesome results. JQUERY has very long list of widgets and plugin and they are pretty easy to implement. One of the commonly used widget is the Accordion. Implementing this in a VF page is not that difficult. But for quick implementation a vf component will be really handy. So here is Visuaforce Components that automatically does all the JQUERY stuff for you and creates a awesome looking Accordion. No javascript coding just include the tags/components and enjoy the JQUERY love. 


How to use the component?
The accordion is generated by the help of two components :
  • <c:Accordion> : This is the wrapper which holds all the accordion section together
  • <c:AccordionSection> : This element actually gets converted into a accordion section.
Below is the code to generate a accordion similar to the attached screen.


<c:Accordion >  
     <c:AccordionSection title="Section 1">  
       Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque.   
       Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh  
       Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada.   
       Vestibulum a velit eu ante scelerisque vulputate.  
     </c:AccordionSection>  
     <c:AccordionSection title="Section 2">  
       Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus.   
       Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit,   
       faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna.  
     </c:AccordionSection>  
   </c:Accordion>  

The plugin is updated to 1.1. The new plugin features a script manager that imports only necessary plugins,script and stylesheet. This mainly helps when multiple Accordion component are used on the same page. Instead of importing the resources multiple times they are imported only once by the script manager.


Wednesday, November 7, 2012


[Live Demo]



Please Note : A Newer Version of this Package is available here http://blogforce9.blogspot.in/2013/10/auto-complete-visualforce-component-v2.html


Well working with visualforce pages, I was always tempted to replace the boring lookup field with a autocomplete component which searches the records as we enter text in them. 

So I sat done and wrote a component for my visualforce pages to replace the boring lookup fields dialogs with autocomplete component.


Few features of the autocomplete component
  • Uses Jquery UI to create the autocomplete component.
  • Look And Feel - Has exactly same look and feel as native components
  • Uses Js Remoting to populate data and hence the component is very fast and light weight.
  • Configurable : The search field can be configured to search fields other than "Name" field. Even the value that is returned to controller can be configured return fields other than record Id.
How to use the component in you Visualforce page?


<c:Autocomplete labelField="Name" valueField="Id" SObject="Contact" targetField="{!targetFieldCon}" /> 

Description
  • labelField : The field which is displayed in the component  and against which matching is done with the entered text. In above code snippet Name is displayed in the autocomplete component.
  • valueField : The field value which is passed back to targetfield when a record is selected.
  • targetField : The field from controller where the selected values is set.
  • SObject : The sobject Api Name against which matching/query is done.
For demo purpose you can check the "autocomplete" vf page that is included in package. This page demonstrates the use of the autocomplete component for different sObjects.

Screen : 




Please Note : A Newer Version of this Package is available here http://blogforce9.blogspot.in/2013/10/auto-complete-visualforce-component-v2.html
Package Link :http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000007rf2z

Saturday, September 8, 2012



10-Sep-2013 : Have a look at my MapMyObject Component, A very flexible Google Map Mapping component.

This is one of the most frequently asked question "How to integrate Salesforce with Google Maps?"
What if you want to show the address of a Say "Account" in the account detail page?
Well the solution is create a inline visualforce page for account and call the google geocoding service to geocode the address ,use that location to mark a point on the map.

Sounds difficult right?
Well in reality its very easy. Just some fancy Java script calls and its done.
Just see the below visualforce page which pulls the Billing Address from the account and displays the same, this page can be included in the Account detail page layout.

Features

  • Shows the Billing Address of the Account in the map
  • On click of the marker a info window is shown with the formatted address.

 <apex:page standardController="Account">  
   <!-- Import Necessary Jquery js File and StyleSheets-->  
   <apex:includeScript value="https://maps.googleapis.com/maps/api/js?sensor=false"/>  
   <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-1.6.2.min.js')}"/>  
   <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-ui-1.8.16.custom.min.js')}"/>  
   <apex:includeScript value="{!URLFOR($Resource.jqPlugin, '/jquery.blockUI.js')}"/>  
   <apex:stylesheet value="{!URLFOR($Resource.jQuery, 'css/ui-lightness/jquery-ui-1.8.16.custom.css')}"/>  
   <script>  
      var map,geocoder,infowindow;  
      var latLngs = [];  
      $j = jQuery.noConflict();   
      $j(document).ready(function(){  
        initialize();  
      });  
      function initialize() {  
       geocoder = new google.maps.Geocoder();  
       //initial cordinates for map init  
       var latlng = new google.maps.LatLng(37.09024, -95.712891);  
       var myOptions = {  
         zoom: 4,  
         center: latlng,  
         mapTypeId: google.maps.MapTypeId.ROADMAP  
       };  
       //load the map  
       map = new google.maps.Map($j('#map')[0], myOptions);  
       codeAddress();  
      }  
      /*This function codes the address using the Billing Address in the Acoount*/  
      function codeAddress(){  
        //prepare a string for geocoding  
        var address = '{!Account.BillingStreet},{!Account.BillingCity},{!Account.BillingCountry},{!Account.BillingPostalCode}';  
        console.log(address);  
        //geocode the address  
        geocoder.geocode( { 'address': address }, function(results, status) {  
          //if it is a success  
          if (status == google.maps.GeocoderStatus.OK) {  
            var location = results[0].geometry.location;  
            var marker=addMarker(location );  
            //attach info window to the marker  
            attachInfoWindow(marker,results[0]);  
          }  
          else {  
            alert(status);  
          }  
        });   
      }  
      /*  
      *This method adds a marker to the provided location  
      **/  
      function addMarker(location) {  
       marker = new google.maps.Marker({  
           position: location,  
           map: map  
         });  
         //set the bounds and initial zoom  
       var latlngbounds = new google.maps.LatLngBounds();  
       latlngbounds.extend(marker.getPosition());  
       map.fitBounds(latlngbounds);  
       map.setZoom(14);  
       return marker;  
      }  
     //this function shows the address of a marker when it is clicked  
     function attachInfoWindow(marker,address){  
        google.maps.event.addListener(marker, 'click', function() {  
          if(infowindow!=null)  
           {  
             infowindow.close();  
           }  
         //HTML formated string that is used to dispaly info window over the map markers currently showing the formated address  
         var contentString = '<div class=" ui-state-active ui-corner-top" style="font-size: 1em; padding: 5px;">Address</div>'  
                   +'<div class="ui-widget-content ui-corner-bottom" style="font-size: .9em; padding: 15px;">'+address.formatted_address+'</div>';  
         infowindow = new google.maps.InfoWindow({  
           content: contentString  
         });  
          infowindow.open(map,marker);  
        });  
     }  
   </script>  
   <style>  
     #map {  
       width:100%;  
       height:200px;   
       margin-left:1.5%;  
     }  
   </style>  
   <div id="map" class="ui-widget-content ui-corner-all ui-state-default"></div>  
 </apex:page>  


How the page looks like?


Page showing the Location of Account


The info window showing the address

Package/Installation
You can use this package to install the same in your org 
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000M5aT
The above package contains a page called LocateAccount that can be used inline in the Account detail page to display the location or you can pass the Id of account to the page like this /apex/LocateAccount?id=<ACCOUNT ID>".


Thursday, August 23, 2012



This Version is no more actively developed and is deprecated. But we have developed two more Alternatives for the same which are much more fun and easy to implement






This is minor change to my Sortable Pageblock Table Component. This change adds some cosmetic changes like the "legendary" up and down arrow to so the direction of sorting.

If you haven't read about this component earlier you can always have a quick glance to my earlier post here .
(You can find details about implementing in the blog)

Demo
You can check the live demo from here(http://blogforce9dev-developer-edition.ap1.force.com/SortablePageblocktable)

Give the Code:
Well you can install the package from here (https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000M3ie)

Screens.




Wednesday, June 13, 2012


[Update : Added Live Demo Links]

In the first part I already described you how to create your own wait/loading screen by blocking the full page.(In case you have missed the first part, you can quickly catch up by reading this blog )

Well what if you want to block specific part of the page ?? Like a pageblock or certain set of fields?? Well jQuery is again here to rescue! The good part of jQuery is it mixes with visualforce very readily to give out awesome results!

So lets see how to make this work using the good old jQuery UI Block Plugin.


 How to block a certain portion of page?

 For demo let us assume that we want to block a pageblock while a ajax request is in progress. To achieve this just give page block a unique id say "pb2Block" and use the same from the jquery ui block. Pass in the id of the pageblock which you want to block to the function, probably from a <apex:actionStatus> like this

Action Status
<apex:actionStatus onstart="blockElement('pb2Block')" onstop="unblockElement('pb2Block')" id="blockElement"/>

Command Button

<apex:commandButton value="Send Request" action="{!processAjaxRequest}" reRender="pb" status="blockElement"/>  

so whenever a ajax request is invoked by a command button the onstart event of the actionStatus is fired which blocks the the pageblock with id "pb2Block" and when the ajax request ends the ontstop event is fired which unblocks the pageblock.


 The JavaScript Functions : The demo visualforce page includes two Javascript function to block and unblock the element

              a) blockElement - takes the Salesforce id of the component to block.
              b)unblockElement - takes the Salesforce id of the component to unblock.



How the Page will look like?


Where is the Code?

Visualforce Page
 <apex:page controller="jQueryUIElementBlockDemo_Con">  
   <!-- Import Necessary Jquery js File and StyleSheets-->  
   <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-1.6.2.min.js')}"/>  
   <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-ui-1.8.16.custom.min.js')}"/>  
   <apex:includeScript value="{!URLFOR($Resource.jqPlugin, '/jquery.blockUI.js')}"/>  
   <apex:stylesheet value="{!URLFOR($Resource.jQuery, 'css/ui-lightness/jquery-ui-1.8.16.custom.css')}"/>  
   <script>  
     $j = jQuery.noConflict();  
     /*  
     *Pass the Id of the element to block   
     **/  
     function blockElement(sfId){   
       $j('[id$='+sfId+']').block({ message: '<img src="/img/loading32.gif" /><h1> Loading...</h1>',   
         css: {   
            border: 'none',   
            padding: '15px',   
            '-webkit-border-radius': '10px',   
            '-moz-border-radius': '10px',   
            opacity: .9  
         }   
       });   
       return false;  
     }  
     /*  
     *Pass the Id of the element to unblock   
     **/  
     function unblockElement(sfId){  
       $j('[id$='+sfId+']').unblock();  
     }  
   </script>  
   <apex:form >  
     <!--In the on start event of action status just call the blockPage method and onstop call the unblockPage js method-->  
     <!--Calling the blockElement js function blocks the page until unblockElement method is called-->  
     <!--Please note that the "Id" of element to black is passed to the js functions--->  
     <apex:actionStatus onstart="blockElement('pb2Block')" onstop="unblockElement('pb2Block')" id="blockElement"/>  
     <apex:sectionHeader title="jQuery UI Element Block Demo" subtitle="This is a demo of jQuery UI block for Blocking Certain portion of a page."/>  
     <apex:pageBlock title="Block This Section" id="pb2Block">  
       <apex:pageBlockSection title="Press the send request button to send a ajax request to the controller/server." collapsible="false">  
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Name</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>  
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Phone</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>   
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Mobile</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>  
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Zipcode</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>     
       </apex:pageBlockSection>  
       <apex:pageBlockButtons id="pb">  
         <!--Note here in the status attribute of command button the id of action status is provided-->  
         <apex:commandButton value="Send Request" action="{!processAjaxRequest}" reRender="pb" status="blockElement"/>  
       </apex:pageBlockButtons>  
     </apex:pageBlock>  
     <apex:pageBlock title="Unblocked Section">  
       <apex:pageBlockSection title="This Page block will remain unblocked" collapsible="false">  
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Name</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>  
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Phone</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>   
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Mobile</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>  
         <apex:pageBlockSectionItem >      
           <apex:outputLabel >Zipcode</apex:outputLabel>  
           <apex:inputText />   
         </apex:pageBlockSectionItem>     
       </apex:pageBlockSection>  
     </apex:pageBlock>  
   </apex:form>  
 </apex:page>  


Apex Controller
public class jQueryUIElementBlockDemo_Con {  
   public void processAjaxRequest(){  
     //Do some processing here  
     for(Integer i =0 ; i < 150000; i++){  
     }  
   }  
   //test method  
   static testMethod void test_ProcessAjaxRequest(){  
     new jQueryUIElementBlockDemo_Con().processAjaxRequest();  
   }  
 }  

Demo

Need more help to implement?

Don't worry packaged a demo visualforce page and all the necessary static resources like jQuery files, jQuery UI Block Plugin. Install the demo page from the here http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000007rfwN




Saturday, June 9, 2012



[Update : Added Live Demo Links]

Ever wondered how to show user a wait or loading message while a ajax call from a visualforce page is in progress?
Well the answer is yes! You can always show a message to user using action status.
What if you want to block the page or some predefined area? Well the solution is jQuery UI block. Using this plugin you can actually block portions of visualforce page while the ajax action is processing.Well the part 1 I am demonstrating how to block the full page while a ajax request is in progress.

How it works?

Very simple from <apex:commandButton/> or <apex:actionFunction/> simply relate a <apex:actionstatus/> component which has a "onstart" and "onstop" event. Call the "blockPage" js function from the "onstart" and call "unblockPage" function from "onstop" attribute.

How the Page will look like?




Visualforce Page


<apex:page controller="jQueryUIBlockDemo_Con">  
   <!-- Import Necessary Jquery js File and StyleSheets-->  
   <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-1.6.2.min.js')}"/>  
   <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-ui-1.8.16.custom.min.js')}"/>  
   <apex:includeScript value="{!URLFOR($Resource.jqPlugin, '/jquery.blockUI.js')}"/>  
   <apex:stylesheet value="{!URLFOR($Resource.jQuery, 'css/ui-lightness/jquery-ui-1.8.16.custom.css')}"/>  
   <script>  
     $j = jQuery.noConflict();  
     //function to block the whole page  
     function blockPage(){   
       $j.blockUI({ message: '<img src="/img/loading32.gif" /><h1> Loading...</h1>',   
         css: {   
          border: 'none',   
          padding: '15px',   
          '-webkit-border-radius': '10px',   
          '-moz-border-radius': '10px',   
          opacity: .9  
         }   
       });   
       return false;  
     }  
     //function to unblock the page  
     function unblockPage(){  
       $j.unblockUI();  
     }  
   </script>  
   <apex:form >  
     <apex:sectionHeader title="Jquery UI Block Demo" subtitle="This is a demo of jQuery UI block for Blocking the whole page when a ajax request is in progress!"/>  
     <!--In the on start event of action status just call the blockPage method and onstop call the unblockPage js method-->  
     <!--Calling the blockPage js function blocks the page until unblockPage method is called-->  
     <apex:actionStatus onstart="blockPage()" onstop="unblockPage()" id="blockUI"/>  
     <apex:pageBlock title="Jquery UI Block Demo">  
       <p>Press the send request button to send a ajax request to the controller/server.</p>  
       <apex:pageBlockButtons id="pb">  
         <!--Note here in the status attribute of command button the id of action status is provided-->  
         <apex:commandButton value="Send Request" action="{!processAjaxRequest}" reRender="pb" status="blockUI"/>  
       </apex:pageBlockButtons>  
     </apex:pageBlock>  
   </apex:form>  
 </apex:page>  


Apex Controller


 public class jQueryUIBlockDemo_Con{  
   public void processAjaxRequest(){  
     //Do some processing here  
     for(Integer i =0 ; i < 10000; i++){  
     }  
   }  
   //test method  
   static testMethod void test_ProcessAjaxRequest(){  
     new jQueryUIBlockDemo_Con().processAjaxRequest();  
   }  
 }  

Demo
You can check the live demo from http://blogforce9dev-developer-edition.ap1.force.com/jQueryUIBlockDemo

Need more help to implement?

Don't worry packaged a demo visualforce page and all the necessary static resources like jQuery files, jQuery UI Block Plugin. Install the demo page from the the Project Detail Page http://blogforce9dev-developer-edition.ap1.force.com/ProjectDetail?id=a0290000007rfwI and go to "jQueryUIBlockDemo". The code is well commented and ready to use.

Tuesday, May 22, 2012


Well few days ago I came across a requirement where on button click user should be asked for confirmation about the action in a modal window. Well we don't have such component in Visualforce!. But hey! Wait! I guess the jquery has it! Why dont we use that one ?

So started mixing Visualforce with Jquery and Result? A modal dialog box!


Well Don get scared its very easy to implement!

Just go to apex/showDialog page for demo and press the showDialog button.

To summarize you can just open a modal window by just calling the openDialog method included in the showDialog page,make sure that you include necessary files while you implement the same in your VF page.

Exp : openDialog('This is a custom dialog','Alert')" ;
Where the first argument is the dialog body and the second is the Dialog title.

Thursday, February 2, 2012


[Update:Added Live Demo Link And Unmanaged package Link]

Talking about the Visualforce component , It has all the component that can make a decent UI but its only limited to the word "DECENT", you can create very rich UI using visualforce.What if  a simple slider needs to be implemented in a Visualforce page? Alas! there are no such component in the standard Visualforce Library.

Well you can create one for yourself using jQuery Library. Talking about jQuery its very stable javascript library with lots of feature! It Readily mixes with visualforce to create very rich UI.

So lets have look on the code to create a simple slider using jQuery.

Visualforce Page

<apex:page controller="jqSlider_Con">  
      <!--Inculding the required jQuery Files and CSS--->  
      <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-1.6.2.min.js')}"/>  
      <apex:includeScript value="{!URLFOR($Resource.jQuery, 'js/jquery-ui-1.8.16.custom.min.js')}"/>  
      <apex:stylesheet value="{!URLFOR($Resource.jQuery, 'css/ui-lightness/jquery-ui-1.8.16.custom.css')}"/>  
      <script>  
        $j = jQuery.noConflict();   
        //this function will be called as soon as page load is complete  
        $j(function(){  
          //calling the createSlider Method to create the slider in designated location  
          createSlider('slider','disp','idInputHidden',0,0,1000);  
       });  
        /*  ----------------------------  
        *  Method to create the Slider  
        *  ----------------------------  
        *  PARAMETERS : "destination" = The Id of the div where the slider needs to be created  
        *         "dispOutput" = The Id of the div where the slider value needs to be displayed  
        *         "idInputHidden" = The Id of the apex inputHidden component  
        *         "startVal" = initial position of slider  
        *         "minVal", "maxVal" = minimum and maximum value of slider  
        **/  
         function createSlider(destination,dispOutput,idInputHidden,startVal,minVal,maxVal){  
           $j("#"+destination).slider({   
             range: false,   
             min: minVal,  
             max: maxVal,  
             values: [startVal],  
             slide: function(event, ui){   
             //This function executes every time slider is moved and applies the slider values   
             //to the input fields as well as the output below the slider  
               $j("[id$="+idInputHidden+"]").val(ui.values[0]);  
               $j("#"+dispOutput).html('$' + ui.values[0]);  
             }  
           });  
           //write the initial value in the display div  
           $j("#"+dispOutput).html('$' + startVal);  
         }   
     </script>  
     <apex:form >  
       <apex:pageBlock title="jQuery Slider">  
         <!--Slider will be created Here-->  
         <div id="slider"/><br/>  
         <!--Slider Output here-->  
         <div id="disp"/>  
         <apex:inputHidden value="{!sSliderField}" id="idInputHidden"/>  
         <apex:pageBlockButtons >  
           <apex:commandButton value="Submit" action="{!checkSliderVal}" reRender="idInputHidden"/>  
         </apex:pageBlockButtons>  
       </apex:pageBlock>  
     </apex:form>  
  </apex:page>  

Controller Class

 public class jqSlider_Con {  
     public String sSliderField { get; set; }  
     public void checkSliderVal(){  
       System.debug('###-------------+'+sSliderField );  
     }  
  }  


About the method "createSlider": In this example I have created a function "createSlider". Which takes in the id of div where the slider neds to be rendered, the id of div where the the values should be displayed, the id of the apex inputHidden(so that values can be passed to controller), the initial value of the slider and range of the slider(max and minimum value).This method can be called multiple times for creating slider in different location of page.




Passing Values to Controller: The values are passed to controller using apex inputHiddent element which assigns the value to a public variable. You can check the communication by clicking the submit button, the value of the slider will assigned to the sSliderField and can be seen in debug logs.


Demo

You can check the live demo by going to 
http://blogforce9dev-developer-edition.ap1.force.com/jQSlider


Package For Installation

Install the demo in your developer Org by using this url : 
https://login.salesforce.com/packaging/installPackage.apexp?p0=04t90000000LxdC