Skip to content

Commit

Permalink
Merge branch 'feature-VALIDATION-8_min_max-if-other-field-value' into…
Browse files Browse the repository at this point in the history
… release-1.3.0
  • Loading branch information
teonator committed Dec 19, 2024
2 parents 8af3fa1 + c8775b9 commit 612144f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion services/validation/ValidationExtrasValidators.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ component {
return "function( value, el, params ) { return true; }";
}

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

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


public boolean function minIfOtherFieldValue( required string fieldName, string value="" ) validatorMessage="cms:validation.min.default" {
if ( ( arguments.data[ arguments.otherField ] ?: "" ) != arguments.otherFieldValue ) {
return true;
}

if ( not Len( Trim( arguments.value ) ) ) {
return true;
}

return Val( Replace( arguments.value, ",", "", "all" ) ) >= arguments.minValue;
}
public string function minIfOtherFieldValue_js() {
return "function( value, el, params ) { return true; }";
}

public boolean function maxIfOtherFieldValue( required string fieldName, string value="" ) validatorMessage="cms:validation.min.default" {
if ( ( arguments.data[ arguments.otherField ] ?: "" ) != arguments.otherFieldValue ) {
return true;
}

if ( not Len( Trim( arguments.value ) ) ) {
return true;
}

return Val( Replace( arguments.value, ",", "", "all" ) ) <= arguments.maxValue;
}
public string function maxIfOtherFieldValue_js() {
return "function( value, el, params ) { return true; }";
}


public boolean function ukPhone( required string fieldName, string value="" ) validatorMessage="validationExtras:validation.ukPhone.default" {
if ( not Len( Trim( arguments.value ) ) ) {
return true;
Expand Down

0 comments on commit 612144f

Please sign in to comment.