fng-bootstrap-datetime 0.12.0-beta.345 → 0.12.0-beta.346

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -409,10 +409,25 @@ angular.module('ui.bootstrap.datetimepicker', ["ui.bootstrap.dateparser", "ui.bo
409
409
  // Set form to dirty when required. Works OK with existing records - hopefully new records will have other field types
410
410
  var watchField = attrs.model + '.' + attrs.fngFldName;
411
411
  var formName = attrs.fngOptName;
412
+ // The model value is normally a string or a Date, but can be something else (e.g. a number, or an invalid Date
413
+ // whose toISOString() throws), so compare on a representation that can always be produced
414
+ function comparable(val) {
415
+ if (typeof val === 'string') {
416
+ return val;
417
+ }
418
+ if (typeof val.toISOString === 'function') {
419
+ try {
420
+ return val.toISOString();
421
+ } catch (e) {
422
+ // Invalid Date - fall through
423
+ }
424
+ }
425
+ return String(val);
426
+ }
412
427
  scope.$watch(watchField, function (newVal, oldVal) {
413
428
  if (scope[formName] && newVal && oldVal && newVal !== oldVal) {
414
- var newComp = (typeof newVal === 'string') ? newVal : newVal.toISOString();
415
- var oldComp = (typeof oldVal === 'string') ? oldVal : oldVal.toISOString();
429
+ var newComp = comparable(newVal);
430
+ var oldComp = comparable(oldVal);
416
431
  if (newComp !== oldComp) {
417
432
  scope[formName].$setDirty();
418
433
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fng-bootstrap-datetime",
3
- "version": "0.12.0-beta.345",
3
+ "version": "0.12.0-beta.346",
4
4
  "description": "datetime input plugin for forms-angular",
5
5
  "main": "fng-bootstrap-datetime.js",
6
6
  "scripts": {