关于validator和ajaxSubmit

使用ajaxSubmit之后 ,用之前ajax的方法,validator不起效果,这种情况需要怎么解决呢?有没有什么方法或者是?


评论区

lyh061619

2017-11-23 21:54

给个例子你参考:package com.platform.admin.agent.user;

import com.platform.base.BaseController;
import com.platform.base.BaseValidator;
import com.jfinal.core.Controller;

/**
* 用户信息验证
* Created by sloft.com on 2016/12/12.
*/
public class AgentUserValidator extends BaseValidator {
@Override
protected void validate(Controller c) {
BaseController cc = (BaseController) c;
if ("GET".equals(cc.getRequest().getMethod())) {
return;
}

setShortCircuit(true);

switch (getActionKey()) {
case "/mbz/login":
validateRequired("username", "userNameMsg", "帐户不能为空");
// validateMobile("username", "userNameMsg", "手机格式不正确");

validateRequired("password", "passwordMsg", "密码不能为空");
// validateCaptcha("captcha", "captchaMsg", "验证码不正确");
break;
case "/admin/password":
validateRequired("password1", "password1Msg", "请输入原始密码");
validateRequired("password2", "password2Msg", "请输入新密码");
break;
case "/admin/user/pass":
validateRequired("pass1", "pass1_msg", "请输入原密码");
validateRequired("pass2", "pass2_msg", "请输入新密码");
break;
case "/admin/user/add":
validateRequired("role", "roleMsg", "请选择所属角色");
if (cc.getPara("role").equals("0")) {
addError("roleMsg", "请选择所属角色");
}

String username = cc.getPara("username");
if (AgentUserService.me.isAccountExists(username)) {
addError("usernameMsg", "该手用户已被注册,请重新输入");
}

if ("admin".equals(username) || "superadmin".equals(username) || "root".equals(username)) {
addError("usernameMsg", "该用户名为系统内置用户,请重新输入");
}

validateRequired("phone", "phoneMsg", "手机号码不能为空");
validateMobile("phone", "phoneMsg", "请输入正确的手机号码");
validateRequired("password", "passwordMsg", "密码不能为空");
validatePassword("password", "passwordMsg", "密码格式不正确,请输入由字母或者下划线组成的格式");
validateString("password", 1, 32, "passwordMsg", "密码不能超过32个字");

validateRequired("nickname", "nicknameMsg", "姓名/昵称不能为空");
validateString("nickname", 1, 32, "nicknameMsg", "昵称不能超过19个字");
break;
case "/admin/user/update":
validateRequired("role", "roleMsg", "请选择所属角色");
if (cc.getPara("role").equals("0")) {
addError("roleMsg", "请选择所属角色");
}
// validateRequired("phone", "phoneMsg", "手机号码不能为空");
// validateMobile("phone", "phoneMsg", "请输入正确的手机号");
validateRequired("password", "passwordMsg", "密码不能为空");
validatePassword("password", "passwordMsg", "密码格式不正确,请输入由字母或者下划线组成的格式");
validateString("password", 1, 32, "passwordMsg", "密码不能超过32个字");

validateRequired("nickname", "nicknameMsg", "姓名/昵称不能为空");
validateString("nickname", 1, 32, "nicknameMsg", "昵称不能超过19个字");
break;
}
}

@Override
protected void handleError(Controller c) {
c.renderJson();
}
}

lyh061619

2017-11-23 21:55

参考下,其次就是你看jquery是否配置对,有没有报错。

六芒星界

2017-11-27 09:15

@lyh061619 谢谢 但是问题不在这里,因为ajaxSubmit原因 所以validator校验不了

热门反馈

扫码入社