Skip to content

Commit

Permalink
Merge pull request #408 from dolzenko/allow-combodate-attrs
Browse files Browse the repository at this point in the history
Allow passing min/maxYear to combodate
  • Loading branch information
eugef committed Jan 22, 2016
2 parents f23c313 + 079ca87 commit 6e3edc2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/demos/combodate/desc.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
You should include additional `moment.js`:

And set `editable-combodate` attribute in editable element.
Custom options supported by [Combodate](https://vitalets.github.io/combodate/) can be provided via `e-*` syntax, e.g. `e-min-year="2015"`.
15 changes: 13 additions & 2 deletions src/js/directives/combodate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ angular.module('xeditable').directive('editableCombodate', ['editableDirectiveFa
inputTpl: '<input type="text">',
render: function() {
this.parent.render.call(this);
var combodate = editableCombodate.getInstance(this.inputEl, {value: new Date(this.scope.$data)});

var options = {
value: new Date(this.scope.$data)
};
var self = this;
angular.forEach(["format", "template", "minYear", "maxYear", "yearDescending", "minuteStep", "secondStep", "firstItem", "errorClass", "customClass", "roundTime", "smartDays"], function(name) {

var attrName = "e" + name.charAt(0).toUpperCase() + name.slice(1);
if (attrName in self.attrs) {
options[name] = self.attrs[attrName];
}
});

var combodate = editableCombodate.getInstance(this.inputEl, options);
combodate.$widget.find('select').bind('change', function(e) {
self.scope.$data = (new Date(combodate.getValue())).toISOString();
});
}
});
}
]);
]);

0 comments on commit 6e3edc2

Please sign in to comment.