Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
Parse normal-looking dates (like 4/5/67) and format them so that Cosm will accept them. The script finds all of the Salsa date fields and adds an onBlur handler to parse and format. Invalid dates are left empty. Doing this relieves the supporter of trying to remember to put in YYYY-MM-DD. This script uses moment.js ( by loadi…
// Script to parse Salsa date fields. This handles the case
// where customers want to use a natural format (4/5/67). Without
// this, error messages can hang stuff up.
// @dependencies (
$(document).ready(function() {
var cdnUrl = '';
function setup() {
$('.salsa_date_input').blur(function() {
var text = $(this).val();
if (text.length == 0) { return; }
var date = moment(text).format('YYYY-MM-DD')
date = date == 'Invalid date' ? '' : date;
if (typeof(moment) == 'undefined') {
$.getScript( cdnUrl, function( data, textStatus, jqxhr ) { setup() });
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.