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.
 
 
 
 
 
 

105 lines
3.6 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('.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 {
  35. $this.on('input propertychange', function () {
  36. var $input = $(this);
  37. if ($input.val()) {
  38. removeErrorMessage($input);
  39. }
  40. });
  41. }
  42. };
  43. $.fn.lrRemoveValidMessage = function () {
  44. removeErrorMessage($(this));
  45. }
  46. $.fn.lrValidform = function () {
  47. var validateflag = true;
  48. var validHelper = learun.validator;
  49. var formdata = $(this).lrGetFormData();
  50. $(this).find("[isvalid=yes]").each(function () {
  51. var $this = $(this);
  52. if ($this.parent().find('.lr-field-error-info').length > 0) {
  53. validateflag = false;
  54. return true;
  55. }
  56. var checkexpession = $(this).attr("checkexpession");
  57. var checkfn = validHelper['is' + checkexpession];
  58. if (!checkexpession || !checkfn) { return false; }
  59. var errormsg = $(this).attr("errormsg") || "";
  60. var id = $this.attr('id');
  61. var value = formdata[id];
  62. //var type = $this.attr('type');
  63. //if (type == 'lrselect') {
  64. // value = $this.lrselectGet();
  65. //}
  66. //else if (type == 'formselect') {
  67. // value = $this.lrformselectGet();
  68. //}
  69. //else {
  70. // value = $this.val();
  71. //}
  72. var r = { code: true, msg: '' };
  73. if (checkexpession == 'LenNum' || checkexpession == 'LenNumOrNull' || checkexpession == 'LenStr' || checkexpession == 'LenStrOrNull') {
  74. var len = $this.attr("length");
  75. r = checkfn(value, len);
  76. } else {
  77. //上传控件验证单独处理
  78. if ($this.attr("type") =="lr-Uploader") {
  79. value = $this.find(".lrUploader-input").text();
  80. }
  81. r = checkfn(value);
  82. }
  83. if (!r.code) {
  84. validateflag = false;
  85. $.lrValidformMessage($this, errormsg + r.msg);
  86. }
  87. });
  88. return validateflag;
  89. }
  90. function removeErrorMessage($obj) {
  91. $obj.removeClass('lr-field-error');
  92. $obj.parent().find('.lr-field-error-info').remove();
  93. }
  94. })(window.jQuery, top.learun);