Reputation: 29474
Umbraco 7 has this date/time picker
How do you reuse that in a custom control to avoid reinventing the wheel?
Currently I only have a plain textbox:
<input type='text' ng-model='validTo' />
Upvotes: 3
Views: 3205
Reputation: 2316
Possibly the easiest way is to instantiate the right editor in the controller and bind it to the umbEditor directive. Your template might include something like this:
<umb-property ng-if="validTo.hasValue" property="validTo.model">
<umb-editor model="validTo.model"></umb-editor>
</umb-property>
while your controller might contain something like this:
$scope.validTo = {
model: null,
existingValue: null,
hasValue: false
};
function buildDateTimePickerModel(alias, label, description) {
return {
editor: "Umbraco.DateTime",
label: label,
description: description,
hideLabel: false,
view: "datepicker",
alias: alias,
value: null,
validation: {
mandatory: false,
pattern: ""
},
config: {
format: "YYYY-MM-DD HH:mm:ss",
pickDate: true,
pickTime: true,
useSeconds: true
}
};
};
$scope.validTo.model = buildDateTimePickerModel('validTo', 'Valid To', 'Enter the Valid To date');
Or something like that. I've not tested it but have derived it from an existing project of mine that implements the ContentPicker on a custom UI in a similar fashion.
You might also find this useful to get an idea of the available config options:
Upvotes: 11