1000hz / bootstrap-validator

A user-friendly HTML5 form validation jQuery plugin for Bootstrap 3
http://1000hz.github.io/bootstrap-validator
MIT License
2.38k stars 1.07k forks source link

Hi if i want to make more custom validation how can i do it? Like.. #658

Open pencsi opened 5 years ago

pencsi commented 5 years ago
$('form[data-toggle="validator"]').validator({
    custom: {
        nextpay_d: function($el) {
            var n_d = $('#nextpay_d').val();
            var n_m = $('#nextpay_m').val();
            var n = isWeekend(n_d, n_m);
            if (n == 6 || n == 0){
                return "This date falls on the weekend!";
            }
        },
        followpay_d: function($e2) {
            var date1 = new Date();
            var date2 = new Date();
            var n_d = $('#nextnextpay_d').val();
            var n_m = $('#nextnextpay_m').val();
            date2.setMonth(n_m-1, n_d);
            var n = isWeekend(n_d, n_m);
            if (n == 6 || n == 0){
                return "This date falls on the weekend!";
            }elseif(date2 <= date1){
                return "This date must be higher!";
            }
        }
    }
});
pencsi commented 5 years ago

But this is not the correct syntax :D pls help meee

canadauto commented 4 years ago

this looks right to me library is having issues with jquery 3 hence if it doesnt trigger custom its because of that $('#Form').validator({ custom: { "invalidnumber": function (data) { var number = data.attr('data-invalidnumber'); console.log("here"); if (data.val() == number) { return number + " is not a valid choice"; } } } })