Skip to content

Commit 43999b6

Browse files
committed
allow to use callback functions as the value of boolean properties of editrules
1 parent 583e85c commit 43999b6

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

js/grid.common.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,10 @@
732732
checkValues: function (val, iCol, customobject, nam, options) {
733733
var edtrul, nm, dft, g = this, p = g.p, colModel = p.colModel, cm, isEmpty = jgrid.isEmpty,
734734
editMsg = getGridRes.call($(g), "edit.msg"), ret,
735+
getPropertyValue = function (propertyName) {
736+
var propValue = edtrul[propertyName];
737+
return $.isFunction(propValue) ? propValue.call(g, options) : propValue;
738+
},
735739
dateMasks = getGridRes.call($(g), "formatter.date.masks");
736740
if (customobject === undefined) {
737741
if (typeof iCol === "string") {
@@ -750,12 +754,12 @@
750754
}
751755
if (edtrul) {
752756
if (!nm) { nm = p.colNames != null ? p.colNames[iCol] : cm.label; }
753-
if (edtrul.required === true) {
757+
if (getPropertyValue("required") === true) {
754758
if (isEmpty(val)) { return [false, nm + ": " + editMsg.required, ""]; }
755759
}
756760
// force required
757-
var rqfield = edtrul.required === false ? false : true;
758-
if (edtrul.number === true) {
761+
var rqfield = getPropertyValue("required") === false ? false : true;
762+
if (getPropertyValue("number") === true) {
759763
if (!(rqfield === false && isEmpty(val))) {
760764
if (isNaN(val)) { return [false, nm + ": " + editMsg.number, ""]; }
761765
}
@@ -767,20 +771,20 @@
767771
if (parseFloat(val) > parseFloat(edtrul.maxValue)) { return [false, nm + ": " + editMsg.maxValue + " " + edtrul.maxValue, ""]; }
768772
}
769773
var filter;
770-
if (edtrul.email === true) {
774+
if (getPropertyValue("email") === true) {
771775
if (!(rqfield === false && isEmpty(val))) {
772776
// taken from $ Validate plugin
773777
filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
774778
if (!filter.test(val)) { return [false, nm + ": " + editMsg.email, ""]; }
775779
}
776780
}
777-
if (edtrul.integer === true) {
781+
if (getPropertyValue("integer") === true) {
778782
if (!(rqfield === false && isEmpty(val))) {
779783
if (isNaN(val)) { return [false, nm + ": " + editMsg.integer, ""]; }
780784
if ((val % 1 !== 0) || (val.indexOf(".") !== -1)) { return [false, nm + ": " + editMsg.integer, ""]; }
781785
}
782786
}
783-
if (edtrul.date === true) {
787+
if (getPropertyValue("date") === true) {
784788
if (!(rqfield === false && isEmpty(val))) {
785789
if (cm.formatoptions && cm.formatoptions.newformat) {
786790
dft = cm.formatoptions.newformat;
@@ -793,12 +797,12 @@
793797
if (!jgrid.checkDate(dft, val)) { return [false, nm + ": " + editMsg.date + " - " + dft, ""]; }
794798
}
795799
}
796-
if (edtrul.time === true) {
800+
if (getPropertyValue("time") === true) {
797801
if (!(rqfield === false && isEmpty(val))) {
798802
if (!jgrid.checkTime(val)) { return [false, nm + ": " + editMsg.date + " - hh:mm (am/pm)", ""]; }
799803
}
800804
}
801-
if (edtrul.url === true) {
805+
if (getPropertyValue("url") === true) {
802806
if (!(rqfield === false && isEmpty(val))) {
803807
filter = /^(((https?)|(ftp)):\/\/([\-\w]+\.)+\w{2,3}(\/[%\-\w]+(\.\w{2,})?)*(([\w\-\.\?\\\/+@&#;`~=%!]*)(\.\w{2,})?)*\/?)/i;
804808
if (!filter.test(val)) { return [false, nm + ": " + editMsg.url, ""]; }

0 commit comments

Comments
 (0)