|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /*
- * 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园(http://www.learun.cn)
- * Copyright (c) 2013-2018 北京泉江科技有限公司
- * 创建人:陈彬彬
- * 日 期:2017.03.16
- * 描 述:表单数据验证完整性
- */
- (function ($, learun) {
- "use strict";
-
- $.lrValidformMessage = function ($this, errormsg) {
- /*错误处理*/
- $this.addClass('lr-field-error');
- $this.parent().append('<div class="lr-field-error-info" title="' + errormsg + '!"><i class="fa fa-info-circle"></i></div>');
- var validatemsg = $this.parent().find('.lr-form-item-title').text() + ' ' + errormsg;
- learun.alert.error('表单信息输入有误,请检查!</br>' + validatemsg);
- if ($this.attr('type') == 'lrselect') {
- $this.on('change', function () {
- removeErrorMessage($(this));
- })
- }
- else if ($this.attr('type') == 'formselect') {
- $this.on('change', function () {
- removeErrorMessage($(this));
- });
- }
- else if ($this.hasClass('lr-input-wdatepicker')) {
- $this.on('change', function () {
- var $input = $(this);
- if ($input.val()) {
- removeErrorMessage($input);
- }
- });
- }
- else if ($this.hasClass('checkbox')) {
- $this.on('change', function () {
- removeErrorMessage($(this));
- });
- }
- else if ($this.hasClass('radio')) {
- $this.on('change', function () {
- removeErrorMessage($(this));
- });
- }
- else {
- $this.on('input propertychange', function () {
- var $input = $(this);
- if ($input.val()) {
- removeErrorMessage($input);
- }
- });
- }
- };
-
- $.fn.lrRemoveValidMessage = function () {
- removeErrorMessage($(this));
- }
-
- $.fn.lrValidform = function () {
- var validateflag = true;
- var validHelper = learun.validator;
- var formdata = $(this).lrGetFormData();
-
- $(this).find("[isvalid=yes]").each(function () {
- var $this = $(this);
-
- if ($this.parent().find('.lr-field-error-info').length > 0) {
- validateflag = false;
- return true;
- }
-
- var checkexpession = $(this).attr("checkexpession");
- var checkfn = validHelper['is' + checkexpession];
- if (!checkexpession || !checkfn) { return false; }
- var errormsg = $(this).attr("errormsg") || "";
-
- var id = $this.attr('id');
- var value = formdata[id];
-
- //var type = $this.attr('type');
- //if (type == 'lrselect') {
- // value = $this.lrselectGet();
- //}
- //else if (type == 'formselect') {
- // value = $this.lrformselectGet();
- //}
- //else {
- // value = $this.val();
- //}
- var r = { code: true, msg: '' };
- if (checkexpession == 'LenNum' || checkexpession == 'LenNumOrNull' || checkexpession == 'LenStr' || checkexpession == 'LenStrOrNull' || checkexpession == 'MinLenStr') {
- var len = $this.attr("length");
- r = checkfn(value, len);
- } else {
- //上传控件验证单独处理
- if ($this.attr("type") =="lr-Uploader") {
- value = $this.find(".lrUploader-input").text();
- }
- r = checkfn(value);
- }
- if (!r.code) {
- validateflag = false;
- $.lrValidformMessage($this, errormsg + r.msg);
- }
- });
- return validateflag;
- }
-
- function removeErrorMessage($obj) {
- $obj.removeClass('lr-field-error');
- $obj.parent().find('.lr-field-error-info').remove();
- }
-
- })(window.jQuery, top.learun);
|