Configuration Options


Parameter Type Default Description
debug bool false If true, Spacer warns you if there is any misuse. For example, if debug is true, Spacer perform extra validation on validation patterns usage and show errors in console. Remember to set it to false in production.
locale string en Locale let Spacer know which resources strings to use for (errors messages and dialog buttons). Right now, Spacer support English and Arabic.
trimValues boolean true When getting input's value, trimValues tells Spacer whereas to trim input's value or not.
timelineFormat string D-M-YYYY Default timeline format. Please refer to MomentJs Formats. Used in timeline validation.
validationCurrentDriver string bootstrap3 Current validation driver. For more details, see Available Validation Drivers
validationDrivers object Hold validation drivers. To add custom driver, please see Custom Validation Drivers.
reValidationDelay integer 500 When input's value is changed, how much should Spacer waits (in milli seconds) before trigger re-validation events.
When input's value changes, re-validation does not occur immediately. Rather, Spacer waits 500 ms listening for another change. If input's value changed within 500 ms, Spacer waits another 500 ms. If 500 ms passed without any changed, Spacer trigger re-validation events immediately.
validationIsLite boolean false Set lite rule globally. For more details, see Lite Rule.
validationCustomRules object Hold validation custom rules. For more details, see Validation Custom Rules
validationPre object Hold pre validation functions. For more details, see Pre Rule
listOfErrorsSelector string #spacer-listOfErrors Dom selector that will be used to show list of errors in listOfErrors validation driver.
dialogCurrentDriver string bootstrap3Panel Current dialog driver. For more details, see Available Dialog Drivers
dialogDrivers object Hold dialog drivers. To add custom driver, please see Custom Dialog Drivers
flashCurrentDriver string ukNotify Current flash driver. For more details, see Available Flash Drivers
flashDrivers object Hold flash drivers.
ajaxHeader object undefined Header that will be attached to ajax requests
ajaxLaravelHeader bool false Add Laravel csrf token to ajax header. CSRF token should be stored in a HTML meta tag:
<meta name="csrf-token" content="token_value">
ajaxOnError function Error callback that will be attached to ajax requests. By default, it is a function that show error message dialog containing http error code
momentLocales object Moment locales. The key is the locale (like ar, es) and the value is moment locale object. Spacer changes moment locale whenever Spacer locale option is changed.

Configuration Functions


Spacer expose several functions to deal with configurations options. Here is the list:

spa.setOptions(options)


This function is used to set configuration options. setOptions receive object contains desired options. Here is an example:

spa.setOptions({
	locale: $('html').attr('lang').toLowerCase(),
	ajaxLaravelHeader: true,
	ajaxOnError: function (jqXHR, textStatus, errorThrown) {
		//process ajax error
	},
	dialogCurrentDriver: 'swearAlert',
	debug: true,
	timelineFormat: 'D/M/YYYY',
	validationCurrentDriver: 'bootstrap3',
});

spa.setDialogCD(driverName)


This function is used to set dialog current driver. setDialogCD receive a driver name. If driver is not found in dialogDrivers configuration option, exception is thrown. Here is an example:

spa.setOptions('alert');

spa.setValidationCD(driverName)


This function is used to set validation current driver. setValidationCD receive a driver name. If driver is not found in validationDrivers configuration option, exception is thrown. Here is an example:

spa.setValidationCD('listOfErrors');

spa.setFlashCD(driverName)


This function is used to set flash current driver. setFlashCD receive a driver name. If driver is not found in flashDrivers configuration option, exception is thrown. Here is an example:

spa.setFlashCD('driverName');

spa.getLocale()


This function is used to get current locale. Here is an example:

var locale = spa.getLocale();

spa.setLocale(locale)


This function is used to set current locale. Here is an example:

spa.setLocale('ar');

spa.isLocale(locale)


This function is used to check if current locale is equal to certain value. isLocale receive locale to compare against. Here is an example:

var isEn = spa.isLocale('en');

spa.getTimelineFormat()


Get the current timelineFormat as string. Here is an example:

var timelineFormat = spa.getTimelineFormat();