Skip to content

Commit 961fa3a

Browse files
committed
gw-require-unique-values.php: Added support for whole-field validation for multi-input fields.
1 parent f507348 commit 961fa3a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

gravity-forms/gw-require-unique-values.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function init() {
5252
add_filter( sprintf( 'gform_field_validation_%s', $this->_args['form_id'] ), array( $this, 'validate' ), 10, 4 );
5353
}
5454

55+
private function get_all_field_ids() {
56+
return array_merge( $this->_args['field_ids'], array( $this->_args['master_field_id'] ) );
57+
}
58+
5559
public function validate( $result, $value, $form, $field ) {
5660

5761
if ( ! $this->is_applicable_field( $field ) ) {
@@ -84,7 +88,7 @@ public function validate( $result, $value, $form, $field ) {
8488
$values = $this->get_group_values( $form, $field->id );
8589

8690
// Check if this should be validated as whole field
87-
$all_field_ids = array_merge( $this->_args['field_ids'], array( $this->_args['master_field_id'] ) );
91+
$all_field_ids = $this->get_all_field_ids();
8892
$validate_as_whole = in_array( $field->id, $all_field_ids );
8993

9094
// If the field has inputs, let's loop through them and check if they are unique.
@@ -200,7 +204,7 @@ public function get_filtered_value( $field, $input_id = null ) {
200204

201205
// When using a field ID (not input ID) for multi-input fields, combine all subfield values into one for validation.
202206
if ( ! $input_id && is_array( $field->inputs ) && is_array( $value ) ) {
203-
$all_field_ids = array_merge( $this->_args['field_ids'], array( $this->_args['master_field_id'] ) );
207+
$all_field_ids = $this->get_all_field_ids();
204208
if ( in_array( $field->id, $all_field_ids ) ) {
205209
$combined_parts = array();
206210
foreach ( $field->inputs as $input ) {

0 commit comments

Comments
 (0)