Skip to content

Commit 8588b3f

Browse files
Merge branch 'feature-VALIDATION-7_requiredifotherfieldsempty' into release-1.3.0
2 parents 7eca52f + cc44566 commit 8588b3f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

services/validation/ValidationExtrasValidators.cfc

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,32 @@ component {
4646
return "function( value, el, params ){ $otherField = $( '[name=' + params[0] + ']' ); if ( !$otherField.length || $otherField.val().length ) { return true; } return ( value.length > 0 ); }";
4747
}
4848

49+
public boolean function requiredIfOtherFieldsEmpty(
50+
required string fieldName
51+
, required struct data
52+
, required string otherFields
53+
, any value = ""
54+
) validatorMessage="cms:validation.conditional.required.default" {
55+
for ( var otherField in ListToArray( otherFields ) ) {
56+
if ( len( arguments.data[ otherField ] ?: "" ) ) {
57+
return true;
58+
}
59+
}
60+
return arguments.data.keyExists( fieldName ) && !IsEmpty( value );
61+
}
62+
63+
public string function requiredIfOtherFieldsEmpty_js() validatorMessage="cms:validation.conditional.required.default" {
64+
return "function( value, el, params ){
65+
var otherFields = params[0].split(',');
66+
for ( var i=0; i<otherFields.length; i++ ) {
67+
var $otherField= $( '[name=' + otherFields[i] + ']');
68+
if ( $otherField.length && $otherField.val().length ) {
69+
return true;
70+
}
71+
}
72+
return ( value.length > 0 );
73+
}";
74+
}
4975

5076
public boolean function requiredIfOtherFieldNotEmpty( required string fieldName, any value="", required struct data, required string otherField ) validatorMessage="cms:validation.conditional.required.default" {
5177
if ( !len( arguments.data[ arguments.otherField ] ?: "" ) ) {
@@ -75,7 +101,7 @@ component {
75101
if ( !len( trim ( lookupValue ) ) || !len( trim( otherFieldValue ) ) ) {
76102
return true;
77103
}
78-
104+
79105
return !( listFindNoCase( lookupValue, otherFieldValue ) && !len( trim( value ) ) );
80106
}
81107
public string function requiredIfOtherFieldMatchSystemLookup_js() {

0 commit comments

Comments
 (0)