Skip to content

Commit

Permalink
Datepicker custom format
Browse files Browse the repository at this point in the history
  • Loading branch information
Alain-es committed May 18, 2015
1 parent 35cb4d5 commit 43f99e1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ function dateTimePickerController($scope, notificationsService, assetsService, a
//map the user config
$scope.model.config = angular.extend(config, $scope.model.config);

$scope.datetimePickerValue = $scope.model.value;

//hide picker if clicking on the document
$scope.hidePicker = function () {
$element.find("div:first").datetimepicker("hide");
//$element.find("div:first").datetimepicker("hide");
// Sometimes the statement above fails and generates errors in the browser console. The following statements fix that.
var dtp = $element.find("div:first");
if (dtp && dtp.datetimepicker) {
dtp.datetimepicker("hide");
}
};
$(document).bind("click", $scope.hidePicker);

Expand Down Expand Up @@ -67,8 +74,16 @@ function dateTimePickerController($scope, notificationsService, assetsService, a
.datetimepicker($scope.model.config)
.on("dp.change", applyDate);

//manually assign the date to the plugin
$element.find("div:first").datetimepicker("setValue", $scope.model.value ? $scope.model.value : null);
//manually assign the date to the plugin
if (!$scope.model.config.format) {
$element.find("div:first").datetimepicker("setValue", $scope.model.value ? $scope.model.value : null);
}
else {
$element.find("div:first").datetimepicker("setValue", $scope.model.value ? new Date($scope.model.value) : null);
if ($scope.model.value && $scope.model.config.format) {
$scope.datetimePickerValue = moment($scope.model.value).format($scope.model.config.format);
}
}

//Ensure to remove the event handler when this instance is destroyted
$scope.$on('$destroy', function () {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="umb-editor umb-datepicker" ng-controller="Umbraco.PropertyEditors.DatepickerController">
<div class="input-append date datepicker" style="position: relative;" id="datepicker{{model.alias}}">
<input name="datepicker" data-format="{{model.config.format}}" type="text"
ng-model="model.value"
ng-model="datetimePickerValue"
ng-required="model.validation.mandatory"
val-server="value" />
<span class="add-on">
Expand Down
13 changes: 10 additions & 3 deletions src/Umbraco.Web/PropertyEditors/DatePropertyEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ public DatePropertyEditor()

private IDictionary<string, object> _defaultPreVals;

/// <summary>
/// Overridden because we ONLY support Date (no time) format and we don't have pre-values in the db.
/// </summary>
public override IDictionary<string, object> DefaultPreValues
{
get { return _defaultPreVals; }
Expand Down Expand Up @@ -60,5 +57,15 @@ public override object ConvertDbToEditor(Property property, PropertyType propert
}

}

protected override PreValueEditor CreatePreValueEditor()
{
return new DatePreValueEditor();
}

internal class DatePreValueEditor : PreValueEditor
{
public string DefaultValue { get; set; }
}
}
}

0 comments on commit 43f99e1

Please sign in to comment.