Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions classes/fields/paragraph.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
die( '-1' );
}

use Pods\Data\Traits\Field_Validation;

/**
* @package Pods\Fields
*/
class PodsField_Paragraph extends PodsField {

use Field_Validation;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -146,6 +150,12 @@ public function options() {
'type' => 'number',
'help' => __( 'Set to -1 for no limit', 'pods' ),
],
static::$type . '_min_length' => [
'label' => __( 'Minimum Length', 'pods' ),
'default' => 0,
'type' => 'number',
'help' => __( 'Set to 0 for no minimum', 'pods' ),
],
static::$type . '_placeholder' => [
'label' => __( 'HTML Placeholder', 'pods' ),
'default' => '',
Expand Down Expand Up @@ -279,6 +289,43 @@ public function input( $name, $value = null, $options = null, $pod = null, $id =

}

/**
* {@inheritdoc}
*/
public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
$validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );

$errors = [];

if ( is_array( $validate ) ) {
$errors = $validate;
}

$check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );

if ( is_array( $check ) ) {
$errors = array_merge( $errors, $check );
} else {
if ( '' !== $value && '' === $check ) {
if ( $this->is_required( $options ) ) {
$errors[] = __( 'This field is required.', 'pods' );
}
}

$min_length_error = $this->get_min_length_error( $check, $name, $options );

if ( null !== $min_length_error ) {
$errors[] = $min_length_error;
}
}

if ( ! empty( $errors ) ) {
return $errors;
}

return $validate;
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions classes/fields/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
die( '-1' );
}

use Pods\Data\Traits\Field_Validation;

/**
* @package Pods\Fields
*/
class PodsField_Text extends PodsField {

use Field_Validation;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -101,6 +105,12 @@ public function options() {
'type' => 'number',
'help' => __( 'Set to -1 for no limit', 'pods' ),
],
static::$type . '_min_length' => [
'label' => __( 'Minimum Length', 'pods' ),
'default' => 0,
'type' => 'number',
'help' => __( 'Set to 0 for no minimum', 'pods' ),
],
static::$type . '_placeholder' => [
'label' => __( 'HTML Placeholder', 'pods' ),
'default' => '',
Expand Down Expand Up @@ -200,6 +210,12 @@ public function validate( $value, $name = null, $options = null, $fields = null,
$errors[] = __( 'This field is required.', 'pods' );
}
}

$min_length_error = $this->get_min_length_error( $check, $name, $options );

if ( null !== $min_length_error ) {
$errors[] = $min_length_error;
}
}

if ( ! empty( $errors ) ) {
Expand Down
47 changes: 47 additions & 0 deletions classes/fields/wysiwyg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
die( '-1' );
}

use Pods\Data\Traits\Field_Validation;

/**
* @package Pods\Fields
*/
class PodsField_WYSIWYG extends PodsField {

use Field_Validation;

/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -170,6 +174,12 @@ public function options() {
'type' => 'text',
'help' => __( 'Format: strong em a ul ol li b i', 'pods' ),
],
static::$type . '_min_length' => [
'label' => __( 'Minimum Length', 'pods' ),
'default' => 0,
'type' => 'number',
'help' => __( 'Set to 0 for no minimum', 'pods' ),
],
];

return $options;
Expand Down Expand Up @@ -402,6 +412,43 @@ function_exists( 'did_filter' )
$this->render_input_script( $args );
}

/**
* {@inheritdoc}
*/
public function validate( $value, $name = null, $options = null, $fields = null, $pod = null, $id = null, $params = null ) {
$validate = parent::validate( $value, $name, $options, $fields, $pod, $id, $params );

$errors = [];

if ( is_array( $validate ) ) {
$errors = $validate;
}

$check = $this->pre_save( $value, $id, $name, $options, $fields, $pod, $params );

if ( is_array( $check ) ) {
$errors = array_merge( $errors, $check );
} else {
if ( '' !== $value && '' === $check ) {
if ( $this->is_required( $options ) ) {
$errors[] = __( 'This field is required.', 'pods' );
}
}

$min_length_error = $this->get_min_length_error( $check, $name, $options );

if ( null !== $min_length_error ) {
$errors[] = $min_length_error;
}
}

if ( ! empty( $errors ) ) {
return $errors;
}

return $validate;
}

/**
* {@inheritdoc}
*/
Expand Down
46 changes: 46 additions & 0 deletions src/Pods/Data/Traits/Field_Validation.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

127 changes: 127 additions & 0 deletions tests/codeception/wpunit/Pods/Field/PodsField_ParagraphTest.php

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading