Skip to content

Fixed issue with Leap Years #7

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

Merged
merged 4 commits into from
Apr 3, 2012

Conversation

mattclements
Copy link
Contributor

29/02/2012 which is a Leap Year (and therefore has 29 days in the month of Febrary) was being shown as an incorrect Date.

This has been resolved in my latest commit (along with the jQuery Library missing, and therefore the examle.html file doesn't instantly work (I have linked to Google CDN to include this so new downloaders can use straight away to evaluate).

I hope you don't mind me doing all these changes, I just love the library, and want to get this to a position where I can use in some new projects I am working on :) :)

Matt Clements added 4 commits April 3, 2012 10:07
Added Google CDN Hosted jQuery latest
29/02/2012 was a Leap Year, but was being shown as an incorrect Date
Also changed minified version and changed to not alter Symbols
UK VAT Number Validation added
@mattclements
Copy link
Contributor Author

I have also fixed the minified version which had shorted the variables causing various issues.

Later commit includes validation for UK VAT Number Validation.

I have tested US Date Format: mm/dd/yyyy which is fine, and European: dd.mm.yyyy and UK Format: dd/mm/yyyy which are all fine (except the Leap Year issue which is also fixed in this Pull Request)

@victorjonsson
Copy link
Owner

No I don't mind - Keep up the great work!

Maybe I will rethink the design of the plugin later on. Both validateSwedishMobileNumber, validateSwedishSecurityNumber and validateUKVATNumber feels like very specific functions. Maybe there should be some sort of modular design.

I my self is using the plugin on some mobile websites. The smaller the files is the better in that case...

A module could look something like:

jQueryFormUtil.addValidator({
  name : 'validateUKVATNumber',
  validate : function(val) {...},
  errorMessage : '....'
});

Im thinking that each module, or set of modules, could be lying in its own file, in the same directory as the jquery form validation plugin. And that you could load them like:

jQueryFormUtil.loadModules('validateUKVATNumber, otherValidationLibrary');

The module loading function will itself create and append the script tag and wait for it to load until calls to $(this).validate() becomes possible. Im guessing this will be version 2.0 of the plugin :)

Once again thank you for the collaboration and the nice code contribution!

victorjonsson added a commit that referenced this pull request Apr 3, 2012
Fixed issue with Leap Years
@victorjonsson victorjonsson merged commit 974b303 into victorjonsson:master Apr 3, 2012
@mattclements
Copy link
Contributor Author

+1 for the modular design idea! This would massively save on resources for Mobile/Low Bandwidth users (especially as I wouldn't need say the Swedish validation, where you wouldn't need UK etc).

I was just thinking of "localised" validation (i.e. en_GB, en_US, se etc), but it seems silly to design it like this as somebody may not need (for example) URL or Domain so it seems silly them downloading these for nothing.

@victorjonsson
Copy link
Owner

I was thinking that the most commonly used functions would be part of the core and that the rest would be distributed as modules.

Possibly keeping these functions as default:

  • validate_url
  • validate_date
  • validate_email
  • validate_int
  • validate_length — min/max
  • validate_confirmation
  • required
  • validate_custom

What do you think?

@mattclements
Copy link
Contributor Author

That sounds good to me! Need to look at how we can load external js files in the most compatible way...

I know that Modernizer etc just created a build page which created a JS file for the user on request which was a minified version with just the functionality they want... but this isn't easily extendable in the future...

@mattclements
Copy link
Contributor Author

We could use something like Google Analytics Async load:

  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 
        'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
  })();

@victorjonsson
Copy link
Owner

Maybe it's better to use the jQuery's function getScript?

Something like:

loadModule = function(modules, path) {
  if(!path) {
     var path = // get relative path of current script file
  }
  $.each(modules.split(','), function(i, module) { 
    $.getScript( path + $.trim(module) + '.js' )
            .fail(function() {
                throw new Error('Unable to load form validation module '+module);
            });
  });  
}
....

jQueryFormUtils.loadModules('date,ukvatnumber,something');

@mattclements
Copy link
Contributor Author

That could work! Are you going to implement, or would you like me to have a go?

@victorjonsson
Copy link
Owner

Give me until tomorrow. I will push it to a separate banch.

@mattclements
Copy link
Contributor Author

Sweeet :)

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

Successfully merging this pull request may close these issues.

2 participants