2015-11-23 59 views
0

我嘗試添加自定義驗證parsley.js:錯誤嘗試添加自定義驗證

window.ParsleyValidator 
    .addValidator('invalidWords', { 
    requirementType: 'regexp', 
    validateString: function(value, requirement) { 
     console.log(value,requirement); 
     return /^\b(?:Stadium|GT|BB|HB|Simul|VNOSE|LT|combination|LT1|SSGT|BW|HBS|simul|combo|2hbs|4d|lt2|theatre)\b$/i.test(value) 
    }, 
    messages: { 
     en: 'Invalid words detected.' 
    } 
    }); 

與HTML作爲...

<div class="col-sm-6 col-lg-6"> 
    <div class="form-group"> 
     <input type="text" name="company" data-parsley-group="eventinfo" id="Company" class="form-control" placeholder="Company" maxlength="60" tabindex="3" title="Company" parsley-trigger="keyup" data-parsley-invalidwords="" value="#request.args.company#"> 
    </div> 
</div> 

我不斷收到錯誤Callback must be instanciated with a function和我不知道爲什麼。我正在關注網站上的指示。 http://parsleyjs.org/doc/index.html#custom 它也似乎無法觸發鍵盤上。 使用版本2.0.7

回答

2

我注意到我是在一個較舊的版本,所以我已更新到2.2-rc4並且問題似乎已解決。