slickgrid validate column with regex

前端 未结 4 661
心在旅途
心在旅途 2021-01-03 08:39

There is a simple sample with column validation:

    function requiredFieldValidator(value) {
      if (value == null || value == undefined || !value.length)         


        
4条回答
  •  醉酒成梦
    2021-01-03 09:29

    By default, you cannot pass more parameters into the validator method, however you can easily edit the source to allow it.

    in slick.editors.js look for:

    this.validate = function () {
      if (args.column.validator) {
        var validationResults = args.column.validator($input.val());
        if (!validationResults.valid) {
          return validationResults;
        }
      }
    
      return {
        valid: true,
        msg: null
      };
    };
    

    change: var validationResults = args.column.validator($input.val());

    to: var validationResults = args.column.validator($input.val(), $input);

    this will change your validator method signature to something like:

    function requiredFieldValidator(value, input)
    

    With that, you can get whatever attributes you want out of input with input.attr('validation-expression') or input.data... or whatever.

提交回复
热议问题