1000hz bootstrap-validator自定义验证

时间:2015-09-09 02:26:34

标签: jquery forms twitter-bootstrap validation bootstrapvalidator

我尝试使用bootstrap验证程序并根据if else语句添加自定义验证程序,但它似乎并没有起作用。也许我对自定义验证的工作原理感到困惑,但我的日志甚至没有出现在控制台中......

JS:

<input class="form-control" type="text" name="address2" id="address2" size="30" placeholder="Your Address" data-distance/>

HTML:

#import <Foundation/Foundation.h>

int main (int argc, const char * argv[])
{
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    [[NSFileManager defaultManager] createFileAtPath:@"E:/NumsToIntFile" contents:nil attributes:nil];

    int num = 0;
    int x = 1;

    printf("\nEnter a number: ");
    scanf("%d", &num);

    while(num >= x)
    {
       NSString *str = [NSString stringWithFormat:@"%d ", x];
       [str writeToFile:"E:/NumsToIntFile" atomically:YES encoding:NSUTF8StringEncoding error:nil];
       x++;
    }

    NSString *contents = [NSString stringWithContentsOfFile:@"E:/NumsToIntFile"];
    NSLog(@"%@",contents);
    [pool release];
    return 0;
} 

1 个答案:

答案 0 :(得分:3)

我需要输入data-distance =&#34; true&#34;在我想要验证的输入上。 console.logs没有出现,因为我把它们放在返回之后。

见这里: http://jsbin.com/nuwajejinu/edit?html,js,console,output

$('#estimate').validator({
  custom: {
    'distance': function() { 
      if( $("#distance-group").hasClass("invalid")){
        console.log("ERROR")
        return false;
      }else{
        console.log("NO ERROR")
        return true;
      }
    }
  },
  errors: {
    'distance': "Nope"
  }
})

HTML:

<input type="text" data-distance="true" id="distance-group" class="form-control" required>
相关问题