WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] [PATCH] Don't show end time as erroneus when it isn't (9 posts)

  1. Daedalon
    Member
    Posted 1 year ago #

    When adding or modifying an event, the end time is shown as erroneous (the textfield box gets a red border and white background) whenever the end time is smaller than the start time. This is incorrect when the end date is a later date than the start date. To show the error only when the end and start dates are the same or end date is not set, locate in includes/js/events-manager.js line 674:

    if(jQuery.timePicker(start).getTime() > jQuery.timePicker(this).getTime()) { end.addClass("error"); }

    and change it to

    if( jQuery.timePicker(start).getTime() > jQuery.timePicker(this).getTime() && ( jQuery('.em-date-end').val().length == 0 || jQuery('.em-date-start').val() == jQuery('.em-date-end').val() ) ) { end.addClass("error"); }

    A further update would be to call this validation also when the dates change. That would require making this its own function, so it'd be best if the core plugin author would make it in the desired way.

    http://wordpress.org/extend/plugins/events-manager/

  2. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    will look into that

    for datepickers, not so straightforward, but you probably want to look at this line -

    jQuery(document).triggerHandler('em_datepicker', datepicker_vals);

    you'd bind an event for em_datepicker to your document

  3. Daedalon
    Member
    Posted 1 year ago #

    Thanks for the quick reply. Managed to do it by taking lines 674-675:

    if(jQuery.timePicker(start).getTime() > jQuery.timePicker(this).getTime()) { end.addClass("error"); }
    			else { end.removeClass("error"); }

    and replacing them with

    if( jQuery.timePicker(start).getTime() > jQuery.timePicker(this).getTime() && ( jQuery('.em-date-end').val().length == 0 || jQuery('.em-date-start').val() == jQuery('.em-date-end').val() ) ){
    				if ( jQuery('.em-date-end').val().length > 0 ) {
    					// Increase end date by one
    					var nextDayDate = new Date();
    					nextDayDate.setDate(jQuery('.em-date-end').datepicker('getDate').getDate() + 1);
    					jQuery('.em-date-end').datepicker('setDate', nextDayDate);
    				} else { end.addClass("error");	}
    			} else { end.removeClass("error"); }

    This increases the end date only if it was the same as the start date. It might be even better to have this update the end date in every case when it's set, but unfortunately I'm running out of time to evaluate the use cases and modify the code as necessary for today. This is already a definite improvement in usability in itself and shouldn't have any drawbacks.

    It might also be worth adding a class to .em-date-end when the update occurs to give the user a visual indicator of what just happened. Perhaps the same visuals would do as what the error class has, what do you think?

    Will this patch (or if not, the previous one) make it into plugin core?

  4. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    probably not, because some users will want datepickers to adjust to the same day. You should try and hook into the event I mentioned above.

  5. Daedalon
    Member
    Posted 1 year ago #

    The patch in the first post doesn't modify the dates. Its only function is to make sure that the end time is indicated as erroneous only when it plausibly is. Would you like to add it into core?

    For the datepicker one I'll see about the event. Thanks!

  6. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    yes, i'll be looking at adding that one asap

  7. Daedalon
    Member
    Posted 1 year ago #

    Great!

  8. Daedalon
    Member
    Posted 1 year ago #

    I wasn't able to use that hook to my advantage.

    jQuery(document).bind('em_datepicker', function(){
    	alert( 'TriggerHandler for "em_datepicker" called.' );
    });

    If I added this to my own script outside the 'main loop' aka jQuery(document).ready(function(){}, it was called only once on document load, never afterwards no matter which date field was changed. If it was placed inside the above, it wasn't called at all.

    What I want to achieve is to hook into the actions that triggers line 670:

    wrap.find(".em-time-range input.em-time-end").change(function() {

    This inside the 'main loop' does the trick:

    jQuery('#end-time').change(function(){
    		alert( 'End-time change() called.' );
    	});

    I was able to make the end date update automatically in certain situations.

    I'm curious about that datepicker TriggerHandler, there might be something to learn here. Is it purposely to be triggered only once? What kind of use case was it created for?

  9. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 1 year ago #

    Yes, this should be triggered only once when the document is loaded, it's in order to change default datepicker options.

    Your solution is perfectly fine too :)

    That's a good point, because it might be that you are putting it inside a jQuery(document).ready... wrapper and it may not get bound before we create the datepickers. This should work on its own as long as after the jQuery library is included.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.