Fixes: U4-3350 Content Validation: Can't get rid of DateTime error

This commit is contained in:
Shannon
2013-11-07 14:58:41 +11:00
parent 345b96e253
commit 3d6eea9470
4 changed files with 25 additions and 12 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using Newtonsoft.Json;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Editors;
@@ -223,7 +224,8 @@ namespace Umbraco.Core.PropertyEditors
var result = TryConvertValueToCrlType(editorValue.Value);
if (result.Success == false)
{
throw new InvalidOperationException("The value " + editorValue + " cannot be converted to the type " + GetDatabaseType());
LogHelper.Warn<PropertyValueEditor>("The value " + editorValue.Value + " cannot be converted to the type " + GetDatabaseType());
return null;
}
return result.Result;
}

View File

@@ -26,17 +26,20 @@ function valServer(serverValidationManager) {
}
}
//subscribe to the changed event of the view model. This is required because when we
//Need to watch the value model for it to change, previously we had subscribed to
//ctrl.$viewChangeListeners but this is not good enough if you have an editor that
// doesn't specifically have a 2 way ng binding. This is required because when we
// have a server error we actually invalidate the form which means it cannot be
// resubmitted. So once a field is changed that has a server error assigned to it
// we need to re-validate it for the server side validator so the user can resubmit
// the form. Of course normal client-side validators will continue to execute.
//TODO: Should we be using $render here instead?
ctrl.$viewChangeListeners.push(function () {
scope.$watch(function() {
return ctrl.$modelValue;
}, function (newValue) {
if (ctrl.$invalid) {
ctrl.$setValidity('valServer', true);
}
});
});
//subscribe to the server validation changes
serverValidationManager.subscribe(currentProperty.alias, fieldName, function (isValid, propertyErrors, allErrors) {

View File

@@ -1,5 +1,5 @@
angular.module("umbraco").controller("Umbraco.PropertyEditors.DatepickerController",
function ($scope, notificationsService, assetsService) {
function ($scope, notificationsService, assetsService, angularHelper) {
//setup the default config
var config = {
@@ -12,17 +12,19 @@ angular.module("umbraco").controller("Umbraco.PropertyEditors.DatepickerControll
//map back to the model
$scope.model.config = config;
function applyDate(e){
function applyDate(e) {
angularHelper.safeApply($scope, function() {
// when a date is changed, update the model
if (e.localDate) {
if ($scope.model.config.format == "yyyy-MM-dd HH:mm:ss") {
$scope.$apply(function(){
$scope.model.value = e.localDate.toIsoDateTimeString();
});
}else{
$scope.model.value = e.localDate.toIsoDateTimeString();
}
else {
$scope.model.value = e.localDate.toIsoDateString();
}
}
});
}
assetsService.loadJs(

View File

@@ -14,8 +14,14 @@ namespace Umbraco.Web.PropertyEditors
{
public IEnumerable<ValidationResult> Validate(object value, PreValueCollection preValues, PropertyEditor editor)
{
//don't validate if empty
if (value == null || value.ToString().IsNullOrWhiteSpace())
{
yield break;
}
DateTime dt;
if (value != null && DateTime.TryParse(value.ToString(), out dt) == false)
if (DateTime.TryParse(value.ToString(), out dt) == false)
{
yield return new ValidationResult(string.Format("The string value {0} cannot be parsed into a DateTime", value),
new[]