You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

115 lines
3.9 KiB

  1. /*
  2. * 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园(http://www.learun.cn)
  3. * Copyright (c) 2013-2018 北京泉江科技有限公司
  4. * 创建人:陈彬彬
  5. * 日 期:2017.03.16
  6. * 描 述:表单数据验证完整性
  7. */
  8. (function ($, learun) {
  9. "use strict";
  10. $.lrValidformMessage = function ($this, errormsg) {
  11. /*错误处理*/
  12. $this.addClass('lr-field-error');
  13. $this.parent().append('<div class="lr-field-error-info" title="' + errormsg + '!"><i class="fa fa-info-circle"></i></div>');
  14. var validatemsg = $this.parent().find('.lr-form-item-title').text() + ' ' + errormsg;
  15. learun.alert.error('表单信息输入有误,请检查!</br>' + validatemsg);
  16. if ($this.attr('type') == 'lrselect') {
  17. $this.on('change', function () {
  18. removeErrorMessage($(this));
  19. })
  20. }
  21. else if ($this.attr('type') == 'formselect') {
  22. $this.on('change', function () {
  23. removeErrorMessage($(this));
  24. });
  25. }
  26. else if ($this.hasClass('lr-input-wdatepicker')) {
  27. $this.on('change', function () {
  28. var $input = $(this);
  29. if ($input.val()) {
  30. removeErrorMessage($input);
  31. }
  32. });
  33. }
  34. else if ($this.hasClass('checkbox')) {
  35. $this.on('change', function () {
  36. removeErrorMessage($(this));
  37. });
  38. }
  39. else if ($this.hasClass('radio')) {
  40. $this.on('change', function () {
  41. removeErrorMessage($(this));
  42. });
  43. }
  44. else {
  45. $this.on('input propertychange', function () {
  46. var $input = $(this);
  47. if ($input.val()) {
  48. removeErrorMessage($input);
  49. }
  50. });
  51. }
  52. };
  53. $.fn.lrRemoveValidMessage = function () {
  54. removeErrorMessage($(this));
  55. }
  56. $.fn.lrValidform = function () {
  57. var validateflag = true;
  58. var validHelper = learun.validator;
  59. var formdata = $(this).lrGetFormData();
  60. $(this).find("[isvalid=yes]").each(function () {
  61. var $this = $(this);
  62. if ($this.parent().find('.lr-field-error-info').length > 0) {
  63. validateflag = false;
  64. return true;
  65. }
  66. var checkexpession = $(this).attr("checkexpession");
  67. var checkfn = validHelper['is' + checkexpession];
  68. if (!checkexpession || !checkfn) { return false; }
  69. var errormsg = $(this).attr("errormsg") || "";
  70. var id = $this.attr('id');
  71. var value = formdata[id];
  72. //var type = $this.attr('type');
  73. //if (type == 'lrselect') {
  74. // value = $this.lrselectGet();
  75. //}
  76. //else if (type == 'formselect') {
  77. // value = $this.lrformselectGet();
  78. //}
  79. //else {
  80. // value = $this.val();
  81. //}
  82. var r = { code: true, msg: '' };
  83. if (checkexpession == 'LenNum' || checkexpession == 'LenNumOrNull' || checkexpession == 'LenStr' || checkexpession == 'LenStrOrNull' || checkexpession == 'MinLenStr') {
  84. var len = $this.attr("length");
  85. r = checkfn(value, len);
  86. } else {
  87. //上传控件验证单独处理
  88. if ($this.attr("type") =="lr-Uploader") {
  89. value = $this.find(".lrUploader-input").text();
  90. }
  91. r = checkfn(value);
  92. }
  93. if (!r.code) {
  94. validateflag = false;
  95. $.lrValidformMessage($this, errormsg + r.msg);
  96. }
  97. });
  98. return validateflag;
  99. }
  100. function removeErrorMessage($obj) {
  101. $obj.removeClass('lr-field-error');
  102. $obj.parent().find('.lr-field-error-info').remove();
  103. }
  104. })(window.jQuery, top.learun);