开发者

events in AnyTime date picker

开发者 https://www.devze.com 2023-02-10 16:19 出处:网络
I want to fire a function w开发者_开发问答hen user clicks on any button under \"Day Of the Month\".

I want to fire a function w开发者_开发问答hen user clicks on any button under "Day Of the Month".

I found out the code for "Hour". But couldn't find the one for month.

The original problem -

I am updating an HTML span with the values selected in the AnyTime picker. I have set up earliest and latest limits. The former includes hours and minutes, the application is a scheduler, so I need only future dates, but not more than week.

I've added a function call on line 624 of anytime.js

This works great. For instance, at 5 PM, if a user selects 18th February with time as 12 AM (default), the span is updated properly. But, if he selects 15th Feb (that's today), "5 pm" gets automatically selected, being the earliest limit and the input is update properly. But there's no call to function (I don't expect one either, I haven't added anything for this).

What should I do to make sure that whenever such situation occurs, the function is called properly?

Thank you,all.


If I understand your question correctly: The function for processing a day-of-month press is defined inline, beginning on line #1579 of anytime.js (the uncompressed version, which you really should be modifying) or beginning on line #236 of anytimec.js (the compressed version, which is harder to figure out).


I think you don't need to modify anything inside anytime.js plugin!

My workaround was to siply rely on datepicker's input "onChange" event, so everytime the input value is updated I get my custom event fired.

input.change( function () { // Update your formatted span here
    $("#my-span").html( this.value.length ? _formatVal(this.value) : "-" );
} );

And formatVal() could be a function to convert the original input format to a more fancy one to display at your span:

function _formatVal( val ) {
    return AnyTime.Converter( {format:'%a %e-%b-%Y'} ).format(
        AnyTime.Converter( {format:'%Y-%m-%d %H:%i:%s'} ).parse( val )
    )
}

Where format '%a %e-%b-%Y' is the one to display at your span, and format '%Y-%m-%d %H:%i:%s' is the original input value format (let's say a DATETIME MySQL field).

Works like a charm for me, hope this helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号