Javascript form-validation framework: Request for Review

前端 未结 2 978
离开以前
离开以前 2021-02-02 16:06

I wasn\'t sure if I could ask this kind of question, but after seeing this on Meta Stackoverflow, it looks like this kind of question is ok. Well, onto my question:

A fe

2条回答
  •  渐次进展
    2021-02-02 16:55

    I like it a lot already, it keeps my html clean and the ability to build custom validators is great. One thing I added was a short hand for binding the validation and submit functions, and wrapped it up as a jQuery plugin:

    if (jQuery) {
        (function($)
        {
            $.regula = function(formId, callback) 
            {
                regula.bind();
    
                $("#" + formId).submit(function() 
                {
                    var validationResults = regula.validate();
    
                    if (validationResults.length > 0)
                    {
                        if (callback)
                            callback(validationResults);
    
                        return false;
                    }
    
                    return true;
                });
            };
        })(jQuery);
    }
    

    Infact, I've just blogged about it to as I am that impressed with how clean and easy it is. I'm still going to spend time going through your source, to see how your accomplished it, but its a great start :)

    In regards to integrating your framework, I work mostly with ASP.NET MVC, and it would be interesting to see how it translate server-side validation logic into client-side constraints. Something I might look over in the next month or so.

提交回复
热议问题