You are currently browsing the category archive for the ‘jQuery’ category.
I try to work on things I am excited about as much as possible because I work “harder, better, faster, stronger.”
Here are a few things I’m excited about at the moment:
(1) Meteor. Recent explosive entry into the Javascript libraries/frameworks, which provides a “railsesque” framework for developing with a Node.js backend and presumably MongoDB datastore. Fills a huge need and appears to do just about everything just right, both in terms of design decisions and community engagement. I predict total domination.
(2) 12 Factor App. Not commented on heavily with the Salesforce community though a product not only of top-notch Heroku smarts but also with commentary from top Salesforce eggheads (e.g. Mountjoy), I think this is the sort of document we will be reviewing in five years as “prophetic.” In many ways, the future is already here, but it will take most of us a long time to realize it.
(3) jQuery. I know that there is nothing new here, but as a diehard jQuery enthusiast, I still think its time of triumph “in the enterprise” is coming soon as people finally get the message (and also realize that UI of their product is important).
(4) Berlin. Not quite Silicon Valley but people are picking up the torch and I expect to see more significant European-based challengers instead of just imitators over the next few years. Don’t doubt the Curry Wurst.
(5) Polyglot solutions. Even though it has often failed to invest substantially in its own open source ecosystem, Salesforce has taken something of a lead in acquiring in the fascinating although occasionally murky world of “polyglot” solutions, where various languages are used to provide what presumably is the “right tool for the job.” Despite the occasionally murkiness and gangs of cheerleaders without any real understanding of the strengths and weaknesses of various technology sets, I’m excited to see more definition about what constitutes the “right tool for the job” and robust composite solutions — of course, expect to see this more on the “bottom up” Heroku side than the typically top-down Salesforce side.
(6) Fractals. Okay, probably you know this already, but I think other people are finally starting to get the message about just how “fractal-eque” many parts of the world are.
New project of mine on Github.
Explanation:
jQuery UI for Salesforce provides a complete set of jQuery powered elements that can be used instead of the standard elements. This includes automatic client-side validation.
A page showing the jQuery elements compared with standard elements can be found here.
Usage
Complete specifications follow for each enhanced component:
Text:
<c:enhancedText pageController="{!this}" fieldName="Text__c" />
You can also force there to be both a uppercase and lowercase letters by telling to to validate as a name:
<c:enhancedText pageController="{!this}" fieldName="Text__c" validateAs="name" />
Email:
<c:enhancedText pageController="{!this}" fieldName="Email__c" validateAs="email" />
Number (Double):
<c:enhancedText pageController="{!this}" fieldName="Number__c" validateAs="number" />
Percent:
<c:enhancedText pageController="{!this}" fieldName="Percent__c" validateAs="percent" />
Checkbox (Boolean):
<c:enhancedCheckbox pageController="{!this}" fieldName="Checkbox__c" />
Phone:
<c:enhancedText pageController="{!this}" fieldName="Phone__c" validateAs="phone" />
Defaults to international phone, for US domestic phone use:
<c:enhancedText pageController="{!this}" fieldName="Phone__c" validateAs="phoneus" />
Picklist:
<c:enhancedSelect fieldName="Picklist__c" pageController="{!this}" object="{!TestObject__c}" /
Multi-Picklist (Multiselect)
<c:enhancedMultiselect pageController="{!this}" fieldName="Picklist_Multi_Select__c" object="{!TestObject__c}" /
Lookup (Reference) :
<c:enhancedLookup pageController="{!this}" fieldName="Test_Lookup_Object__c" objectToLookup="TestLookupObject__c" />
Lookup (Reference) :
<c:enhancedLookup pageController="{!this}" fieldName="Test_Lookup_Object__c" objectToLookup="TestLookupObject__c" />
Textarea :
<c:enhancedTextarea pageController="{!this}" fieldName="Text_Area__c" expandable="true" width="145" height="50" />
Controller:
(1) Install enhanced components via unmanaged package install link.
(2) Have your main controller (which can be a standard controller) extend PageControllerBase:
public with sharing class DemoPageController extends PageControllerBase
If you want to use a standard controller include this:
public DemoPageController(ApexPages.StandardController controller) {
standardCon = controller;
this.myObject = controller.getRecord();
}
Then include this function:
// First we save the values from the Enhanced Component controllers, then whatever standard fields there are.
// If you are using standard fields in addition to enhanced components, whichever method is utilizing fields required by the API should always be in the first position
public PageReference save()
{
ecSave();
standardCon.save();
return null;
}
Page:
Include your favorite jQuery UI theme easily:
<apex:stylesheet value="{!URLFOR($Resource.JQueryUICup,'development-bundle/themes/cupertino/jquery.ui.all.css')}"/>
See how standard themes will look by choosing the switch theme option on this page. You can also easily create your own theme with Themeroller.
On your page you will also need to enable validation.
The easiest way is to assign a form styleClass element to your form declaration:
<apex:form styleClass="form" >
Then just before you close your form tag add an action function:
<apex:actionFunction action="{!pageController.save}" name="saveMe"></apex:actionFunction>
</apex:form>
Then add the automatically generated javascript:
<apex:outputText escape="false" value="{!pageController.completeJavascript}"/>
This line will not only add hotlinks to the Google and Microsoft CDNs (for JQuery, JQueryUI and JQuery validation plugin), it will enable validation any form with a form class and add all of the necessary methods for validation.
If you don’t want to use the automagic client-side validation, hotlink the necessary CDNs manually:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"/>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.1/jquery-ui.min.js"/>
Here is a list of all of the Plugins currently included:
JQuery UI 1.8
JQuery Validation (Joern Zaefferer)
Autocomplete 1.1.1 (Joern Zaefferer)
Expandable 1.0 (Brandon Aaron)
Select Menu (Filament Group)
Multiselect 0.6 (Eric Hynds)
I stayed up until around three in the morning one night last week finishing this super addictive and awesome tutorial by jQuery creator John Resig.
I’ve been through some little ditty tutorials on closures and had people attempt to explain what it is before, but Resig’s tutorial is to your average online tutorial what a tanto is to a wiener.
Even though in a certain sense I’ve never met a wiener I didn’t like, I’d prefer that if you were fighting on my side you had a proper weapon –
and no matter how many skillz you got, it always helps to sharpen them.
Part of the reason I like this approach so much is that there is very little unnecessary baggage. You figure out what you need to by reading the code, with a few quizzes where you write some code so that the lessons sink in. As things stand I think the quizzes are a little bit under-developed, and as a whole it could probably be a bit more content as far as examples and gradually developing a theme, but hey JResig has a whole book coming out soon. Another fantastic feature is that you can edit each example as you go along, so if something is not immediately obvious you can tweak it or can add in the necessary log statements.
As far as this goes, I believe this is the future of programming education (and education in general). Less paper, less explanation, more interaction, more cementing of the material. In other words, less talking, more doing.
Keep in mind this is a Ninja-level tutorial, so it assumes a fair bit of knowledge of Javascript that you probably won’t have if you’ve just been waving around a wiener. That said and despite some rough edges, I will repeat and say it is the best online tutorial I have ever seen.
Here are some highlights:
Context – One of the funkier bits of JS.
Closures – Show don’t tell. Love it!
Function Prototypes – A lot you can do here but tricky to get right
Inheritance – You have to understand this well if you are doing any Advanced Javascript
Truly awesome is when you get to see how all the building blocks fit together towards the end of the book as Resig appropriate builds up to (rather than dissects) the Prototype bind function.
I end with this beautiful example:
var ninja = {
yell: function(n){
return n > 0 ? ninja.yell(n-1) + "a" : "hiy";
}
};
In case you were wondering, we are hiring ninjas over at Tquila.
We announce KittenForce, yet another Fractastical Labs production. KittenForce provides furry placeholder images for your page as follows:
<c:kitten myHeight="200" myWidth="200" />
The result is quite predictable.

Meow!
If you are more bold you might try something like the following:
<c:kitten myHeight="200" myWidth="200" darylShaber="true" />
If you are curious to see what your page would look like without any of the usual Salesforce images, try this:
<c:kitten myHeight="400" myWidth="300" applyToAll="true" />
I don’t recommend doing this with Daryl. Although you can…
Install KittenForce here.
Special thanks to PlaceKitten and Lsemel. Source can be found on Github.
Since loading large numbers of records proved impossible, I’ve updated my jQuery autocomplete integration to perform an Ajax call and retrieve associated records on key press.
Benefits:
(1) Live Ajax autocomplete on any object
(2) Easy to use
(3) Easily themable with jQuery Themeroller
(4) Easily customizable (implementation is open source)
(5) Can provide a filter
Usage:
<c:enhancedLookup pageController="{!this}" fieldName="Test_Lookup_Object__c" objectToLookup="TestLookupObject__c" bigset="true" />
Defaults are:
(1) 2 characters must be typed in before the call
(2) Call with ‘LIKE’ as specified in Abhinav Gupta’s helpful post on the subject
(3) Lookup on 8 elements while the string is under 3 characters and 100 after this
To provide a filter pass a filter string in SOQL format such as the following:
<c:enhancedLookup pageController="{!this}" fieldName="Test_Lookup_Object__c" objectToLookup="TestLookupObject__c" bigset="true" filterString="WHERE type__c != 'Bear'" />
I’ve added this and numerous other enhancements to the jQuery for Salesforce library at Google Code.
I’ve also added the controller to my library on Snipplr for reference.
Setting up jqGrid is not terribly difficult, but customizing it can be somewhat more difficult. Take this paragraph from the wiki article on search:
There are four approaches:
* a toolbar searching
* a custom searching
* a single field searching
* a more complex approach involving many fields and conditions – advanced searchingThese approaches use common options from jqGrid and so can be called only on an already-constructed grid. Every search method requires that some additional module should be included into the package. Also refer to Download or in every specific module on what should be included
But there are no links to article on the different search modules and the download page does not include any more details.
What to do? Here’s a working search function partially provided by Trirand support:
<script type="text/javascript">
$.jgrid.no_legacy_api = true;
$.jgrid.useJSON = true;
</script>
<script type="text/javascript">
function searchContact(letter, field, oper)
{
if(!oper) oper = 'bw';
// build the filter
var filter = {"groupOp":"OR","rules":[{"field":"FirstName","op":oper,"data":letter},{"field":"Lastname","op":oper,"data":letter},{"field":"Phone","op":oper,"data":letter}] };
$("#Contactdatatable").jqGrid('setGridParam',{search:true, postData:{filters:filter} } );
$("#Contactdatatable").trigger("reloadGrid");
return false;
}
</script>
Here is what a modified version looks like in my Salesforce component:
function search{!uid}(arg, field, oper)
{
if(!oper) oper = 'bw';
if(field)
$enhanced{!uid}.jqGrid('setGridParam',{search:true, postData:{searchOper:oper,searchField:field, searchString:arg}});
else {
var filter = {"groupOp":"OR","rules":{!colRulesJson} };
$enhanced{!uid}.jqGrid('setGridParam',{search:true, postData:{filters:filter} });
}
$enhanced{!uid}.trigger("reloadGrid");
return false;
}
An editable, searchable implementation for Salesforce has just been finished as part of something I am working on for the Salesforce Foundation:
Soon to be generally available.


