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
Override the default for dateParser / dateFormatter? #459
Comments
Yeap, the default is |
Hi @rxaviers, What I'm wondering is is there away to override the default? To make it |
It's clear now, thanks. Will read your use case better when I find time and get back to you. |
Thanks @rxaviers! |
@johnnyreilly, I didn't fully understand the relationship between overriding the default dateParser / dateFormatter options and how this should solve the mapping between 0.x to 1.x date patterns (ways to express a date)? |
@rxaviers essentially it's about not having to specify a date format each time the parsing takes place or pass in one format right at the start. Ideally I don't want to require users to pass a date format to jquery.validation.globalize.js on initialisation. Rather, I would like to be able to rely on the default dateParser. If users can configure the default then they would be able to control that and implicitly control the date parsing that jquery.validation.globalize.js does. Obviously there's other approaches but controlling the default seems like it would be a useful feature anyway. The "out-of-the-box" default doesn't seem too useful as it stands. Does that make sense? |
Can't this be configured at the validator scope? For example: $.validator.methods.dateDefaultOptions = null;
$.validator.methods.date = function (value, element) {
var val = Globalize.parseDate(value, $.validator.methods.dateDefaultOptions);
return this.optional(element) || (val instanceof Date);
}; Globalize dateParser / dateFormatter default mimics ecma-402 default. |
That's probably good enough for me. Let me try it out and report back. Though, my use case aside i think the existing fixed default doesn't add much value. But if you're seeking to align with a spec then fair enough I guess. |
Awesome. Just let me know if something else pops up. |
Hi @rxaviers, I've just been giving it a go and unfortunately I had to start again from scratch (long story). Anyway, I've used Bower to upgrade to 1.0.0 and I have a I've read and re-read the cldr-data-bower documentation but for the life of me I can't figure out how I actually get the CLDR data itself. Could you clarify it for me please? For what it's worth I don't understand what this actually means:
"dependencies": {
"foo-number-format": "1.2.3",
"bar-date-format": "4.5.6"
} In the example what are "foo-number-format" and "bar-date-format"? Could you share a real world example perhaps? I added the |
Cracked it (I think). To make it work you need to delete your local Hey presto cldr-data. I didn't seem to need any dependencies:
I wonder if it might be worth highlighting in the docs that if you should remove all bower stuff and reinstall if you want to pull the cldr-data down. What do you think? |
Hey @johnnyreilly, thanks for raising these points up. Quick answer, it didn't work because you might have run Longer answer: Developers can use any tool to fetch CLDR data being The current discussion of this issue is diverging from its original scope. So, I'm closing it.
Sure, feel free to submit a PR with a suggestion. I'm sure there are improvements to be done that will help users to overcome these questions. Although, I am not convinced about the remove and reinstall thing. I guess you ran I want to emphasize that your help has been very much welcome and appreciated so far and I'm looking forward to further contributions. Thanks |
Hi @rxaviers, I'll try and submit a docs PR when I get a moment. Cheers. |
Awesome, thanks |
Hi,
I've been having a play with Globalize 1.x with a view to finally migrating jquery-validation-globalize over to it. To do this I've focussing on date parsing and number parsing - that's the only functionality of Globalize that jquery-validation-globalize uses.
There's a big jump involved in switching from Globalize 0.1 to Globalize 1.x (it turns out getting set up with Globalize 1.x is no small feat!). I'm hoping to do my best to make the switch in using jquery-validation-globalize as painless as possible.
The existing jquery-validation-globalize takes Globalize as a dependency and swaps out the various validation methods to use Globalize for number and date parsing. There's really very little to it - I enclose the source for clarity:
As you can probably tell this relies on Globalize having been initialised to the required
culture
(that'slocale
in 1.x). It looks like I can take a similar approach by initialising Globalize 1.x to the required locale.From my initial testing it seems that I can just swap out usage of
parseFloat
and replace it withparseNumber
as per the migration guide. Since numbers are pretty straightforward it looks this this just works. (further testing still required)However, dates are not so straightforward as there's a million and one ways to express a date. So, my question: is there a way to specify default dateParser / dateFormatter options? Looking at the source code I suspect the answer is "not right now".
Which is a shame. Would it be possible to have this ability? This would make migration of jquery-validation-global more straightforward and would, I suspect, be a generally useful thing. I tend to use only one date formatting / parsing style and so I would much rather have the ability to set this during initialisation and then rely on this behaviour subsequently. It also seems an good thing to have given that you already have the concept of a default locale as a possibilty.
The text was updated successfully, but these errors were encountered: