diff --git a/index.html b/index.html index 1415fb9..ffaea17 100644 --- a/index.html +++ b/index.html @@ -67,6 +67,7 @@

LegalForm.js demo

+ diff --git a/js/lib/dot-key.js b/js/lib/dot-key.js new file mode 100644 index 0000000..5a18d88 --- /dev/null +++ b/js/lib/dot-key.js @@ -0,0 +1,54 @@ + +if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { + module.exports = { setByKeyPath, getByKeyPath }; +} + +/** + * Set (nested) property of object using dot notation + * + * @param {object} target + * @param {string} key + * @param value + */ +function setByKeyPath(target, key, value) { + var parts = key.split('.'); + + for (var i = 0; i < parts.length; i++) { + var part = parts[i]; + + if (i < parts.length -1) { + if (typeof target[part] !== 'object') { + target[part] = {}; + } + + target = target[part]; + } else { + target[part] = value; + } + } +} + +/** + * Get (nested) property of object using dot notation + * + * @param {object} target + * @param {string} key + * @param defaultValue + */ +function getByKeyPath(target, key, defaultValue) { + if (!target || !key) return false; + + key = key.split('.'); + var l = key.length, + i = 0, + p = ''; + + for (; i < l; ++i) { + p = key[i]; + + if (target.hasOwnProperty(p)) target = target[p]; + else return defaultValue; + } + + return target; +} diff --git a/js/ractive-legalform.js b/js/ractive-legalform.js index c645cc5..b69e13d 100644 --- a/js/ractive-legalform.js +++ b/js/ractive-legalform.js @@ -417,20 +417,51 @@ }) }, + /** + * Get values that should replace ractive values + */ + getRewriteValues: function() { + var values = {}; + + $(this.elWizard).find('[data-picker="date"]').each(function() { + var $inputGroup = $(this); + var $input = $inputGroup.find('input'); + + var yearly = !!$input.attr('yearly'); + if (yearly) return; + + var value = $input.val(); + var date = moment(value, 'DD-MM-YYYY', true); + var isoDate = date.utc().format('YYYY-MM-DDTHH:mm:ssZ'); + + var name = $input.attr('name'); + values[name] = isoDate; + }); + + return values; + }, + /** * Init date picker */ initDatePicker: function () { var ractive = this; + var $wizard = $(this.elWizard); + + $wizard.find('[data-picker="date"]').each(init); //do on page init, to convert date format from ISO + $wizard.on('click', '[data-picker="date"]', init); //do for fields, that were hidden on page init - $(this.elWizard).on('click', '[data-picker="date"]', function(e) { + function init(e) { var $inputGroup = $(this); if ($inputGroup.data('DateTimePicker')) return; var yearly = $inputGroup.find('input').attr('yearly'); + var format = yearly ? 'DD-MM' : 'DD-MM-YYYY'; + $inputGroup.datetimepicker({ locale: ractive.getLocale('short'), - format: yearly ? 'DD-MM' : 'DD-MM-YYYY', + format: format, + extraFormats: ['YYYY-MM-DDTHH:mm:ssZ'], //Allow ISO8601 format for input dayViewHeaderFormat: yearly ? 'MMMM' : 'MMMM YYYY', //Allow arrow keys navigation inside date text field @@ -446,8 +477,10 @@ } }); - $(e.target).closest('.input-group-addon').trigger('click'); - }); + if (typeof e !== 'undefined') { + $(e.target).closest('.input-group-addon').trigger('click'); + } + } }, /** @@ -605,7 +638,6 @@ var validator = $stepForm.data('bs.validator'); if (!validator) { - console.log('Reinitializing validator...'); self.initBootstrapValidation(); self.updateBootstrapValidation(); return; @@ -1099,56 +1131,6 @@ callback(key, meta); } - /** - * Set (nested) property of object using dot notation - * - * @param {object} target - * @param {string} key - * @param value - */ - function setByKeyPath(target, key, value) { - var parts = key.split('.'); - - for (var i = 0; i < parts.length; i++) { - var part = parts[i]; - - if (i < parts.length -1) { - if (typeof target[part] !== 'object') { - target[part] = {}; - } - - target = target[part]; - } else { - target[part] = value; - } - } - } - - /** - * Get (nested) property of object using dot notation - * - * @param {object} target - * @param {string} key - * @param defaultValue - */ - function getByKeyPath(target, key, defaultValue) { - if (!target || !key) return false; - - key = key.split('.'); - var l = key.length, - i = 0, - p = ''; - - for (; i < l; ++i) { - p = key[i]; - - if (target.hasOwnProperty(p)) target = target[p]; - else return defaultValue; - } - - return target; - } - /** * Build object of http headers from headers names and values * @param {array|string} names Headers names diff --git a/live-contract.html b/live-contract.html index cd0fdbd..800851e 100644 --- a/live-contract.html +++ b/live-contract.html @@ -67,6 +67,7 @@

LegalForm.js demo

+ diff --git a/material.html b/material.html index 3cab179..3ac3c8a 100644 --- a/material.html +++ b/material.html @@ -66,6 +66,7 @@

LegalForm.js demo with Material Design

+ diff --git a/nomaterial.html b/nomaterial.html index 8f1feb8..6a97449 100644 --- a/nomaterial.html +++ b/nomaterial.html @@ -77,6 +77,7 @@

LegalForm.js demo with Material Design

+