如何在bootstrap中的文本字段前显示错误消息

时间:2015-03-18 06:13:55

标签: validation message

function saveAdmin(){
  var adminObj = form2js('adminUserFrm', '.', true);      

  var $adminModal = $('div#admin-modal');
  var $adminFrm = $adminModal.find('form#adminUserFrm');
  var request = performAJAX($adminFrm.attr('action'), adminObj, true, 'text');
  request.done(function(resData) {    
      console.log('Request Success'); 
      createAutoClosingAlert($adminModal.find('.alert-success'), 3000);
      closeModal(1000);
      $('div#admin-list').html(resData);
  });

  request.fail(function(jqXHR, textStatus) {
     addErrors($adminModal.find('.alert-info'), jqXHR);


  });     
}

这是我保存管理员的功能

如果服务器验证失败,我想在特定字段前显示错误消息。

控制器:

@RequestMapping(value = "/register-new-admin", method = RequestMethod.POST)
public ModelAndView registerNewAdmin(Model model,
        @RequestBody AdminUserDTO adminUserDTO, BindingResult result)
        throws InvalidParameterException {
    LOG.info("Entering to method registerNewAdmin");
    adminUserValidator.validate(adminUserDTO, result);
    if (result.hasErrors()) {

        throw new InvalidParameterException(
                getAllFieldErrorMsg(result.getAllErrors()));
    }
    List<AdminUserDTO> adminUserList = adminUserBo
            .saveAdminUserFromDTO(adminUserDTO);

    model.addAttribute("updatedAdminUserList", adminUserList);

    return adminUserPage(model,0, 50, adminUserDTO.getFullName());
}

0 个答案:

没有答案