Show Dialog Alert
Dialog.showAlert('This is a dialog alert');
Show Dialog Alert with custom styling
Dialog.showAlert("<span class='fontred'>This is a dialog alert with red text</span>", true);
Show custom dialog
Dialog.show('Thank You for using ampersand<br>You have made the right choice', '', 300, true, 1000, true, 'Welcome to ampersand');
To consume templates in javascript you can use the following to read from template files:
var template = Templates.get(url_to_template);
The templating functionality caches the template when loaded first time and all the subsequent calls to get the template will get it from cache.
To fill template with data you can use underscore template method:
var compiled = _.template(template, {firstName: 'John', lastName: 'Smith'});
To validate fields in a form just add validation class to each field you want to validate. For different kinds of validations you have to add respective validation classes to the fields. Validations included in this library are:
validation
validate-required
validate-number
validate-money
validate-positive-number
validate-email
validate-digits
validate-compare
validate-minlength
validate-maxlength
Validation triggers when the field loses focus. It has its pre-defined set of validation error messages for each validation. If you want to specify your own error message you can do it by adding an attribute which is of format data-{validation name}-message . For example for required field validation you can specify as data-required-message .
data-{validation name}-message
If you want to validate the entire form before submitting it, you can do it using:
Validation.validateForm(form_id)
Validation has its own styling. If you want to apply your own styling, please see css/validation.css.
css/validation.css
I have built some helper functions on top of jQuery ajax and jQuery ajax form to extract some functionalities which are commonly used:
Ajax.callHandler(type, url, data, callback, isGlobal, async, errorHanlder)
Ajax.getJson(url, data, callback, isGlobal, async, errorHanlder)
Ajax.postForJSON(url, data, callback, isGlobal, async, errorHanlder)
Arguments for above methods:
For more details on jQuery ajax refer to https://api.jquery.com/jQuery.ajax/
I have added one method on top of jquery ajax form to simplify its usage:
Ajax.ajaxForm(id, success, beforeSubmit, errorHanlder)
Arguments for this method:
For more details on jQuery ajax forms refer to http://malsup.com/jquery/form/#options-object
To help make web development faster, I have provided a css library with commonly used styling as classes. It becomes easy to use these classes for apply uniform style accross pages than defining classes individually.
Youy can see css/helper.css for all these classes. Some of them are:
Again these are few examples of what's available in the helper css. For full reference see css/helper.css.
css/helper.css