Skip to content

Commit 612144f

Browse files
committed
Merge branch 'feature-VALIDATION-8_min_max-if-other-field-value' into release-1.3.0
2 parents 8af3fa1 + c8775b9 commit 612144f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

services/validation/ValidationExtrasValidators.cfc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ component {
108108
return "function( value, el, params ) { return true; }";
109109
}
110110

111-
public boolean function requiredIfOtherFieldInValues( required string fieldName, any value="", required struct data, required string otherField, required string otherFieldValues ) validatorMessage="cms:validation.conditional.required.default" {
112111

112+
public boolean function requiredIfOtherFieldInValues( required string fieldName, any value="", required struct data, required string otherField, required string otherFieldValues ) validatorMessage="cms:validation.conditional.required.default" {
113113
var otherValues = ListToArray( arguments.otherFieldValues );
114114
if ( ( !ArrayContains( otherValues, arguments.data[ arguments.otherField ] ?: "" ) ) ) {
115115
return true;
@@ -129,6 +129,37 @@ component {
129129
}
130130

131131

132+
public boolean function minIfOtherFieldValue( required string fieldName, string value="" ) validatorMessage="cms:validation.min.default" {
133+
if ( ( arguments.data[ arguments.otherField ] ?: "" ) != arguments.otherFieldValue ) {
134+
return true;
135+
}
136+
137+
if ( not Len( Trim( arguments.value ) ) ) {
138+
return true;
139+
}
140+
141+
return Val( Replace( arguments.value, ",", "", "all" ) ) >= arguments.minValue;
142+
}
143+
public string function minIfOtherFieldValue_js() {
144+
return "function( value, el, params ) { return true; }";
145+
}
146+
147+
public boolean function maxIfOtherFieldValue( required string fieldName, string value="" ) validatorMessage="cms:validation.min.default" {
148+
if ( ( arguments.data[ arguments.otherField ] ?: "" ) != arguments.otherFieldValue ) {
149+
return true;
150+
}
151+
152+
if ( not Len( Trim( arguments.value ) ) ) {
153+
return true;
154+
}
155+
156+
return Val( Replace( arguments.value, ",", "", "all" ) ) <= arguments.maxValue;
157+
}
158+
public string function maxIfOtherFieldValue_js() {
159+
return "function( value, el, params ) { return true; }";
160+
}
161+
162+
132163
public boolean function ukPhone( required string fieldName, string value="" ) validatorMessage="validationExtras:validation.ukPhone.default" {
133164
if ( not Len( Trim( arguments.value ) ) ) {
134165
return true;

0 commit comments

Comments
 (0)