2

我不知道爲什麼Form.Validate類沒有在輸入失敗時觸發事件。這是一個簡單的測試,我做了:Mootools Form.Validate沒有觸發事件

HTML

<form id="IndicatorIndexForm" action=""> 
    <input type="text" id="IndicatorKilometers" data-validators="minLength:10" name="data[Indicator][kilometers]"/> 
    <input type="submit" value="Valider" class=""> 
</form> 

JS

var myForm = new Form.Validator($('IndicatorIndexForm'), { 
    onFormValidate: function(resp,form,e){ 
     console.log('error'); 
    }, 
    elementFail: function(el,errors){ 
     console.log('elementFail'); 
     console.log(el); 
     console.log(errors); 
    }, 
    elementValidate: function(resp,el,validator,is_warning){ 
     console.log('elementValidate'); 
     console.log(resp); 
     console.log(el); 
     console.log(validator); 
     console.log(is_warning); 
    } 
}); 

但是當我提交表單,在控制檯中我只看到 「錯誤」 。如果我理解了文檔的相關性,它還應該激發其他兩個功能......我覺得我忘記了一些東西......任何想法?

在此先感謝

這裏的的jsfiddlehttp://jsfiddle.net/HJX3K/2/

回答

1

肯定。您缺少on事件的前綴:

var myForm = new Form.Validator($('IndicatorIndexForm'), { 
    onFormValidate: function(resp,form,e){ 
     console.log('error'); 
    }, 
    onElementFail: function(el,errors){ 
     console.log('elementFail'); 
     console.log(el); 
     console.log(errors); 
    }, 
    onElementValidate: function(resp,el,validator,is_warning){ 
     console.log('elementValidate'); 
     console.log(resp); 
     console.log(el); 
     console.log(validator); 
     console.log(is_warning); 
    } 
}); 
+0

._。 ......就像我的老師曾經說過的:「當你在js中出現錯誤時,99%的時間是你的錯,而不是mootool的」..謝謝:) – pleasedontbelong