There are lot of jquery plugin which we use in our projects like jQuery ui, Number Formatter, mask, select2 etc. One of the simple pattern is to use these plugins through out the application is to make a common javascript file which defines rules by id or class.

For example we use jquery ui datepicker in our application using the following approach.

I have a common file setting.js which is included in main layout. This is the rule i have defined for adding a datepicker to a textfield.


Now in order to use the same all I do is to add a class to my textfield and everything falls in place.

Now all we need to do is to add “dateField” class on any text field it will become the jquery datepicker. We can follow the same approach for other plugins.