基于年份的jQuery UI datepicker验证

时间:2016-11-03 09:45:01

标签: jquery jquery-ui datepicker jquery-ui-datepicker

当用户在我的日历UI日期选择器中选择2016年时,我需要收到错误消息。我正在使用jQuery插件来处理错误消息。 这是我的剧本:

public class LogRepository : ILogRepository
{
    protected CloudTable table;
    //ctor that initialize the azure table
    public LogRepository(string tableName, string connectionString)
    {
        if (string.IsNullOrEmpty(tableName) || string.IsNullOrEmpty(connectionString))
            throw new ArgumentException()

        var storageAccount = CloudStorageAccount.Parse(connectionString);
        var tableClient = storageAccount.CreateCloudTableClient();

        table = tableClient.GetTableReference(tableName);
        table.CreateIfNotExists();
    }
    //read from table and Cast the rows to LogModel
    public IEnumerable<LogModel> GetLogs()
    {
        var query = new TableQuery<LogEntityWrapper>();
        var entities = table.ExecuteQuery(query);
        //The Cast doesn't break laziness
        return entities.Cast<LogModel>();
    }

    // A minimal wrapper, just the implementations of Read and Write Entity
    private class LogEntityWrapper : LogModel, ITableEntity
    {
        public void ReadEntity(IDictionary<string, EntityProperty> properties, OperationContext operationContext)
        {
            TableEntity.ReadUserObject(this, properties, operationContext);
        }

        public IDictionary<string, EntityProperty> WriteEntity(OperationContext operationContext)
        {
            return TableEntity.WriteUserObject(this, operationContext);
        }
    }
}

这是我的HTML:

$(document).ready(function(){
    $("#datepicker").click(function(){

        $("#datepicker").datepicker({
            changeMonth: true,
            changeYear: true,
            yearRange: "1930:2016",
            dateFormat : 'dd-mm-yy'
        });

        $( "#datepicker" ).datepicker("show");
    });
});

1 个答案:

答案 0 :(得分:5)

您可以使用编写here的解决方案在datepicker上找到所选年份。找到日期后,您可以检查并发送错误消息。

在另一种意义上,您可以获取总值并从值中提取(因为您正在定义deatFormat)。你可以通过错误取决于那个。

希望它有所帮助.. :)