Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo usage of the date_format option? #14

Open
jasondavis opened this issue Mar 27, 2015 · 2 comments
Open

Demo usage of the date_format option? #14

jasondavis opened this issue Mar 27, 2015 · 2 comments

Comments

@jasondavis
Copy link

Great little library, thanks for sharing with the world!

In your docs you have put this as an option....

date_format: allows you to output a custom date format from the chosen Date object (defaults to MM/DD/YYYY)

At first I thought this meant passing a string value something like 'MM/DD/YYYY' but when that failed and I looked at the sourcecode and saw that date_format is a Function, I then tried setting a function for this options but I never was able to get the right format to not throw a bunch of console errors.

From the sourcecode initial default setting I can see that it is set with a function like this...

  date_format: function(date) {
    return [date.getMonth() + 1, date.getDate(), date.getFullYear()].join("/");
  },

I have tried re-arranging those values with my own passed in date_format function however I never could get it to work.

Could you please share a quick demo of how to use and set a custom date format please? I have tried 20 combinations with no luck so I could use the help!

@jasondavis
Copy link
Author

UPDATE....

It turns out that none of my custom options werir working! I thought the library had a bug in it but now after lots of testing, I see the problem I had.

I have a Task list which could be anywhere from 1 to 100+ fileds on a page that need a Date Picker like this attached to!

Each of these items is added to the DOM after the DOM has loaded. So in my JavaScript creation process that is creating my "Task" and inserting them into the DOM, that is where I then attach an instance of this Date Picker library to the fields for each record.

The result is that it works great, with the exception that any custom options passed in are strangley ignored!

Now when I do a test with a single form field using this library and do not have to attach it after the DOM is loaded, then all my custom options work!

So I was able to get the date_format and all other options to work on the library, just not where I need them, not yet anyways.

If you or anyone has any suggestions for a solution to my situation, I would love to hear ideas!

@Raicuparta
Copy link

In case anyone comes across this issue like I did, the correct way to do it is something like this pretty straightforward if you look at the source, as jason said):

$input.minical({date_format: date_dd_mm_yyyy});

// format minical dates to DD/MM/YYYY
function date_dd_mm_yyyy(date) {
    return [date.getDate(), date.getMonth() + 1, date.getFullYear()].join("/");
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants