Bind when date is a valid value

pull/16651/head
Salih 2 years ago
parent 848f591cae
commit 402861f4f4

@ -23,10 +23,36 @@ public abstract class AbpDatePickerBaseTagHelperService<TTagHelper> : AbpTagHelp
where TTagHelper : AbpDatePickerBaseTagHelper<TTagHelper>
{
protected readonly Dictionary<Type,Func<object,string>> SupportedInputTypes = new() {
{typeof(string), o => DateTime.Parse((string)o).ToString("O")},
{typeof(DateTime), o => ((DateTime) o).ToString("O")},
{typeof(string), o =>
{
if(o is string s && DateTime.TryParse(s, out var dt))
{
return dt.ToString("O");
}
return string.Empty;
}
},
{typeof(DateTime), o =>
{
if(o is DateTime dt && dt != default)
{
return dt.ToString("O");
}
return string.Empty;
}
},
{typeof(DateTime?), o => ((DateTime?) o)?.ToString("O")},
{typeof(DateTimeOffset), o => ((DateTimeOffset) o).ToString("O")},
{typeof(DateTimeOffset), o =>
{
if(o is DateTimeOffset dto && dto != default)
{
return dto.ToString("O");
}
return string.Empty;
}
},
{typeof(DateTimeOffset?), o => ((DateTimeOffset?) o)?.ToString("O")}
};

@ -64,10 +64,14 @@ public class AbpDatePickerTagHelperService : AbpDatePickerBaseTagHelperService<A
protected override void AddBaseTagAttributes(TagHelperAttributeList attributes)
{
if (TagHelper.AspFor != null &&
TagHelper.AspFor.Model != null &&
TagHelper.AspFor.Model != null &&
SupportedInputTypes.TryGetValue(TagHelper.AspFor.Metadata.ModelType, out var convertFunc))
{
attributes.Add("data-date", convertFunc(TagHelper.AspFor.Model));
var convert = convertFunc(TagHelper.AspFor.Model);
if(!convert.IsNullOrWhiteSpace())
{
attributes.Add("data-date", convert);
}
}
}

@ -619,9 +619,9 @@
options.separator = separator;
}
if(options.autoUpdateInput){
fillInput($input, startDate, endDate, options);
}
fillInput($input, startDate, endDate, options);
$input.on('apply.daterangepicker', function (ev, picker) {
if (singleDatePicker) {

Loading…
Cancel
Save