1

有没有一种方法可以像普通的 jquery ajax 一样自定义远程验证?

$('#banner').bootstrapValidator({
        framework: 'bootstrap',


        fields: {
            bannerType: {
                icon: false,
                validators: {
                    notEmpty: {
                        message: 'Banner type is required'
                    }
                }
            },
            bannerTitle: {
                icon: false,
                validators: {
                    notEmpty: {
                        message: 'Banner title is required'
                    }
                }
            },

            bfromDate: {
                verbose: true,
                validators: {
                     notEmpty: {
                        message: 'From date is required'
                    },
                    date: {
                        format: 'MM/DD/YYYY',
                        message: 'The value is not a valid date'
                    },
                    remote: {
                    url: '/assets/cfc/exchange/exchangeintra.cfc?method=checkAvailabilityofDates',
                    type: 'POST',
                    dataType:'json',
                     data: function(validator, $field, value) {
                            return {

                                selectedDate: validator.getFieldElements('bfromDate').val(),
                                bannerId: validator.getFieldElements('bannerId').val(),



                            };
                        },

                  }
                }
            },
            btoDate: {
                verbose: true,
                validators: {
                     notEmpty: {
                        message: 'To date is required'
                    },
                    date: {
                        format: 'MM/DD/YYYY',
                        message: 'The value is not a valid date'
                    },
                    remote: {
                    url: '/assets/cfc/exchange/exchangeintra.cfc?method=checkAvailabilityofDates',
                    type: 'POST',
                    dataType:'json',
                    data: function(validator, $field, value) {
                            return {

                                selectedDate: validator.getFieldElements('btoDate').val(),
                                bannerId: validator.getFieldElements('bannerId').val(),


                            };
                        },

                  }
                }
            },
             authorImage: {
                validators: {
                     notEmpty: {
                        message: 'Banner image is required'
                    },
                    file: {
                        extension: 'jpeg,jpg,png',
                        type: 'image/jpeg,image/png',
                        message: 'The selected file is not valid'
                        }
                }
            },
            bannerLink: {
                icon: false,
                validators: {
                    notEmpty: {
                        message: 'Banner link is required'
                    }

                }
            }


        }


    });

当远程验证成功时比做任何其他事情,如果失败比做其他事情。

我有以下链接: http: //formvalidation.io/examples/using-data-returned-validator/

但它是有效的,只有当我使用 formvalidation 但在这里我使用 bootstrapValidator.so 有没有办法像 formvalidation 一样做同样的事情。

4

1 回答 1

0

字段验证完成后,它会调用 onSuccess 或 onError 回调。以下是解决我的问题的示例代码:

 bfromDate: {
                verbose: true,
                validators: {
                     notEmpty: {
                        message: 'From date is required'
                    },
                    date: {
                        format: 'MM/DD/YYYY',
                        message: 'The value is not a valid date'
                    },
                    remote: {
                    url: '/assets/cfc/exchange/exchangeintra.cfc?method=checkAvailabilityofDates',
                    type: 'POST',
                    dataType:'json',

                    data: function(validator, $field, value) {
                            return {
                                startDate:0,
                                selectedDate: validator.getFieldElements('bfromDate').val(),
                                bannerId: validator.getFieldElements('bannerId').val(),
                                endRangeFlag:0,
                            };
                        },

                  } 

                },
                onSuccess: function(e, data) {
                   $( "#btoDate" ).prop( "disabled", false ); 

                },
                 onError: function(e, data) {
                     $( "#btoDate" ).val('');
                   $( "#btoDate" ).prop( "disabled", true ); 
                }
          }
于 2016-04-29T14:59:26.760 回答