jtsage / jtsage-datebox

A multi-mode date and time picker for Bootstrap (3&4), jQueryMobile, Foundation, Bulma, FomanticUI, and UIKit (or others)
http://datebox.jtsage.dev/
Other
474 stars 166 forks source link

Fully document and refine what calFormatter actually does #452

Closed jtsage closed 5 years ago

jtsage commented 5 years ago

Looking at #356, there is a fair bit of intended functionality. Most of it works. document it.

Things that should be in the passed object:

What should be returned?

What scope?

This currently runs detached, but it would probably make life way easier if it ran in the context of the widget, you could do:

this.setTheDate()

rather than

$(element).datebox('setTheDate', ...);
jtsage commented 5 years ago

Ok. bit of an update.

calFormatter is a function that gets a single argument of the display object. in it is:

{
  // the theme class to be applied to the date
  theme    : [String]
  // The date is in the current month displayed.
  inBounds : [boolean]
  // True if the date is valid
  good     : [boolean],
  // True if the date is invalid
  bad      : [boolean],
  // Set to the rule that failed the date, or false
  failrule : [boolean|String],
  // Set to the rule that passed the date, or false.
  // Note: both failrule and passrule may be empty if the date passed by default (not explicitly)
  passrule : [boolean|String],
  // The current date being processed.
  dateObj  : [JavaScript Date Object]
}
jtsage commented 5 years ago

What should be returned?

jtsage commented 5 years ago

Things that should be in the passed object:

From the above list, things that are:

Things that are not, because they are easily accessible in the this context.

var firstGridDate = this.getCalStartGrid();
var lastGridDate = this.getCalEndGrid();
// These are identical.  Note the copy, as it is a *mutable* object.
var userSelectedDate = this.originalDate.copy();
var userSelectedDate = this.getSelectedDate();
// These are identical.  Note the copy, as it is a *mutable* object.
var workingDate = this.theDate.copy();
var workingDate = this.getTheDate();
var isSelectedVisible = this.isSelectedInCalGrid();
jtsage commented 5 years ago

Note:

Also changed the context of calBeforeAppendFunc() to be the widget as well, so the same rules of running datebox functions inside that callback apply.