easyui動態新增validType
阿新 • • 發佈:2019-02-12
有時候有些驗證值的可能需要實現,動態新增validType,本以為直接$('#price').numberbox('options').validType = 'length[4]';就可以了,百般嘗試後都不行,決定除錯原始碼,除錯時發現根本不是從numberbox物件中獲取的options,而是從另一個input物件獲取的驗證,便修正了程式碼,併成功實現動態新增validType,以numberbox為例,程式碼如下
普通form表單中動態新增驗證方式為:
$('#orderPurPrice').numberbox('textbox').validatebox('options').validType="lessThanOrEqualsNumber["+price+"]";
datagrid內動態新增驗證方式為:
var selections = getSelections(grid,false);//自己封裝的方法,同grid.datagrid('getSelections'); if (selections != undefined) { for (var i = 0, len = selections.length; i < len; i++) { var selection = selections[i]; var index = grid.datagrid("getRowIndex", selection); grid.datagrid("beginEdit", index); var ed = grid.datagrid('getEditor', {index:index,field:'purPrice'}); $(ed.target).numberbox('textbox').validatebox('options').validType="lessThanOrEqualsNumber["+selection.basePrice+"]";//重要的在這裡,為輸入框新增驗證,lessThanOrEqualsNumber為自定義驗證 } }