0

我试图将表单元素集中在 mouseup 上,或者在 mousedown 上调用表单验证函数后单击。我不知道如何将无效的表单元素集中在单击提交按钮上——这会验证表单。

"#submit_button mousedown" : function(el, ev) { 
        if(!validateForm()){
            return;
        }
"validateForm": function(){
        if($('#firstName').val().length<1){
            $('#firstName').next('label.error').remove();
            $('#firstName').addClass('text-error');
            $('#firstName').closest('div.control-group').children('label.control-label').addClass('label-error');
            $('#firstName').after('<label class="error" data-i18n="account.field_required"></label>'); 
            $('label.error').i18n();
            return false;
        } else {
            return true;
        }
}

"#myForm input blur": function(el, ev){           
        var currentId = el[0].id;
        var currentValue = el.val();
        $(el).next('label.error').remove();
        if($(el).is('input')){ $(el).removeClass('text-error'); }
        if($(el).is('select')){ $(el).removeClass('select-error'); }
        $(el).closest('div.control-group').children('label.control-label').removeClass('label-error');
        if(currentId=="firstName" || currentId=="lastName"){
            if(currentValue.length<1){
                $('#'+currentId).addClass('text-error');
                $('#'+currentId).closest('div.control-group').children('label.control-label').addClass('label-error');
                $('#'+currentId).after('<label class="error" data-i18n="account.field_required"></label>');
                $('label.error').i18n();
        } else {
            return;
        }
}

"#submit_button mouseup" : function(el, ev) { 
    steal.dev.log('mouseup called');
    if(!validateForm()){
        steal.dev.log('account form invalid');
        var fieldErrors = ($('#myForm input.text-error').length>0) ? $('#myForm input.text-error') : $('#myForm input.select-error');
        $('#'+fieldErrors[0].id).focus();
        return;          
    }
},

我不知道为什么除非单击两次,否则无效元素不会集中在 mouseup 上。

谢谢,

Ĵ

4

0 回答 0