From 35d1ab0f8838b2d748a560a4bb727273d45fb3da Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:41:20 -0600 Subject: [PATCH 1/7] Add failing test: list-fields rejects string-keyed options and array default_value Co-Authored-By: Claude Sonnet 5.5 --- .../test_FrmAbilitiesFieldsController.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php b/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php index 647d7b496d..55f96aaf5b 100644 --- a/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php +++ b/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php @@ -110,6 +110,50 @@ public function test_a_field_round_trips_through_create_list_update_delete() { $this->assertArrayNotHasKey( $created['field_key'], $after, 'A deleted field should no longer be listed.' ); } + /** + * Choice options keyed by option text and array defaults are what Formidable stores, + * so list-fields must not reject them, or one such field fails the whole form. + * + * @return void + */ + public function test_list_fields_accepts_string_keyed_options_and_array_default_values() { + $select_id = FrmField::create( + array( + 'form_id' => $this->form->id, + 'type' => 'select', + 'name' => 'Location', + 'options' => array( + '1' => array( + 'label' => '', + 'value' => '', + ), + 'Asheville' => array( + 'label' => 'Asheville', + 'value' => 'asheville', + ), + 'other_1' => 'Other', + ), + ) + ); + $address_id = FrmField::create( + array( + 'form_id' => $this->form->id, + 'type' => 'address', + 'name' => 'Address', + 'default_value' => array( + 'line1' => '1 Main St', + 'city' => 'Asheville', + ), + ) + ); + + $listed = $this->execute( 'list-fields', array( 'form_id' => $this->form->id ) ); + + $this->assertNotWPError( $listed, 'list-fields should validate for string-keyed options and array default values.' ); + $this->assertArrayHasKey( FrmField::getOne( $select_id )->field_key, $listed ); + $this->assertArrayHasKey( FrmField::getOne( $address_id )->field_key, $listed ); + } + /** * @return void */ From 72ba6cd41c090a21513bf9f7f44af9017553a1bf Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:41:42 -0600 Subject: [PATCH 2/7] Widen list-fields output schema for string-keyed options and array default_value Co-Authored-By: Claude Sonnet 5.5 --- .../controllers/FrmAbilitiesFieldsController.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/classes/controllers/FrmAbilitiesFieldsController.php b/classes/controllers/FrmAbilitiesFieldsController.php index 147b0323a6..0afa5c4d5b 100644 --- a/classes/controllers/FrmAbilitiesFieldsController.php +++ b/classes/controllers/FrmAbilitiesFieldsController.php @@ -76,16 +76,14 @@ private static function register_list_fields_ability() { 'description' => __( 'Field type (text, textarea, radio, checkbox, dropdown, email, number, date, file, etc.)', 'formidable' ), ), 'default_value' => array( - 'type' => 'string', - 'description' => __( 'Default value for the field', 'formidable' ), + 'type' => array( 'string', 'array', 'object' ), + 'description' => __( 'Default value for the field. An array or object for fields with several values, such as Address or a multi-select checkbox.', 'formidable' ), ), 'options' => array( - 'type' => 'array', - 'description' => __( - 'Field choices: strings, or {"label", "value"} objects when using separate values. Star rating and scale choices are numbers.', - 'formidable' - ), - 'items' => array( 'type' => array( 'string', 'number', 'object' ) ), + 'type' => array( 'array', 'object' ), + 'description' => __( 'Field choices: strings, or {"label", "value"} objects when using separate values. Star rating and scale choices are numbers. An object keyed by option key when the keys are not sequential.', 'formidable' ), + 'items' => array( 'type' => array( 'string', 'number', 'object' ) ), + 'additionalProperties' => array( 'type' => array( 'string', 'number', 'object' ) ), ), 'field_order' => array( 'type' => 'integer', From 1fbdcdbfd995a4b1753a0858c518b89963bd9b90 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:42:17 -0600 Subject: [PATCH 3/7] Give the select field in the schema test a realistic default_value Co-Authored-By: Claude Sonnet 5.5 --- .../phpunit/fields/test_FrmAbilitiesFieldsController.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php b/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php index 55f96aaf5b..d66e97d1bc 100644 --- a/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php +++ b/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php @@ -119,10 +119,11 @@ public function test_a_field_round_trips_through_create_list_update_delete() { public function test_list_fields_accepts_string_keyed_options_and_array_default_values() { $select_id = FrmField::create( array( - 'form_id' => $this->form->id, - 'type' => 'select', - 'name' => 'Location', - 'options' => array( + 'form_id' => $this->form->id, + 'type' => 'select', + 'name' => 'Location', + 'default_value' => '', + 'options' => array( '1' => array( 'label' => '', 'value' => '', From e7974ca3482417f78000f252c5dc762069eef1be Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:45:49 -0600 Subject: [PATCH 4/7] Shorten list-fields schema descriptions to the 180-char line limit Co-Authored-By: Claude Sonnet 5.5 --- .../controllers/FrmAbilitiesFieldsController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/classes/controllers/FrmAbilitiesFieldsController.php b/classes/controllers/FrmAbilitiesFieldsController.php index 0afa5c4d5b..19b823a798 100644 --- a/classes/controllers/FrmAbilitiesFieldsController.php +++ b/classes/controllers/FrmAbilitiesFieldsController.php @@ -77,13 +77,16 @@ private static function register_list_fields_ability() { ), 'default_value' => array( 'type' => array( 'string', 'array', 'object' ), - 'description' => __( 'Default value for the field. An array or object for fields with several values, such as Address or a multi-select checkbox.', 'formidable' ), + 'description' => __( 'Default value for the field. An array or object when the field holds several values, such as Address.', 'formidable' ), ), 'options' => array( 'type' => array( 'array', 'object' ), - 'description' => __( 'Field choices: strings, or {"label", "value"} objects when using separate values. Star rating and scale choices are numbers. An object keyed by option key when the keys are not sequential.', 'formidable' ), - 'items' => array( 'type' => array( 'string', 'number', 'object' ) ), - 'additionalProperties' => array( 'type' => array( 'string', 'number', 'object' ) ), + 'description' => __( + 'Radio, dropdown, or checkbox choices: strings, or {"label", "value"} objects when using separate values. An object keyed by option key when the keys are not sequential.', + 'formidable' + ), + 'items' => array( 'type' => array( 'string', 'object' ) ), + 'additionalProperties' => array( 'type' => array( 'string', 'object' ) ), ), 'field_order' => array( 'type' => 'integer', @@ -174,10 +177,10 @@ private static function register_create_field_ability() { 'formidable' ), 'items' => array( - 'type' => array( 'string', 'number', 'object' ), + 'type' => array( 'string', 'object' ), ), 'additionalProperties' => array( - 'type' => array( 'string', 'number', 'object' ), + 'type' => array( 'string', 'object' ), ), ), 'default_value' => array( From 939d2b180f40ec03fdc5b1159c195c9b9fa7911d Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 15:45:58 -0600 Subject: [PATCH 5/7] Shorten the options description further Co-Authored-By: Claude Sonnet 5.5 --- classes/controllers/FrmAbilitiesFieldsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/classes/controllers/FrmAbilitiesFieldsController.php b/classes/controllers/FrmAbilitiesFieldsController.php index 19b823a798..b5f3b6b0f6 100644 --- a/classes/controllers/FrmAbilitiesFieldsController.php +++ b/classes/controllers/FrmAbilitiesFieldsController.php @@ -82,7 +82,7 @@ private static function register_list_fields_ability() { 'options' => array( 'type' => array( 'array', 'object' ), 'description' => __( - 'Radio, dropdown, or checkbox choices: strings, or {"label", "value"} objects when using separate values. An object keyed by option key when the keys are not sequential.', + 'Radio, dropdown, or checkbox choices: strings, or {"label", "value"} objects when using separate values. Or an object keyed by option key.', 'formidable' ), 'items' => array( 'type' => array( 'string', 'object' ) ), From 450bea8482f209fea0e42502a1d634c93fc4e01d Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Fri, 16 Oct 2026 16:11:06 -0600 Subject: [PATCH 6/7] Allow a NULL default_value in list-fields, fix options description Co-Authored-By: Claude Sonnet 5.5 --- .../controllers/FrmAbilitiesFieldsController.php | 4 ++-- .../fields/test_FrmAbilitiesFieldsController.php | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/classes/controllers/FrmAbilitiesFieldsController.php b/classes/controllers/FrmAbilitiesFieldsController.php index b5f3b6b0f6..dce538f75f 100644 --- a/classes/controllers/FrmAbilitiesFieldsController.php +++ b/classes/controllers/FrmAbilitiesFieldsController.php @@ -76,13 +76,13 @@ private static function register_list_fields_ability() { 'description' => __( 'Field type (text, textarea, radio, checkbox, dropdown, email, number, date, file, etc.)', 'formidable' ), ), 'default_value' => array( - 'type' => array( 'string', 'array', 'object' ), + 'type' => array( 'string', 'array', 'object', 'null' ), 'description' => __( 'Default value for the field. An array or object when the field holds several values, such as Address.', 'formidable' ), ), 'options' => array( 'type' => array( 'array', 'object' ), 'description' => __( - 'Radio, dropdown, or checkbox choices: strings, or {"label", "value"} objects when using separate values. Or an object keyed by option key.', + 'Radio, dropdown, or checkbox choices: strings, or {"label", "value"} objects when using separate values, or an object keyed by option key.', 'formidable' ), 'items' => array( 'type' => array( 'string', 'object' ) ), diff --git a/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php b/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php index d66e97d1bc..61f1910865 100644 --- a/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php +++ b/tests/phpunit/fields/test_FrmAbilitiesFieldsController.php @@ -111,8 +111,8 @@ public function test_a_field_round_trips_through_create_list_update_delete() { } /** - * Choice options keyed by option text and array defaults are what Formidable stores, - * so list-fields must not reject them, or one such field fails the whole form. + * Choice options keyed by option text, array defaults and a NULL default are what Formidable + * can store, so list-fields must not reject them, or one such field fails the whole form. * * @return void */ @@ -147,12 +147,20 @@ public function test_list_fields_accepts_string_keyed_options_and_array_default_ ), ) ); + $text_id = FrmField::create( + array( + 'form_id' => $this->form->id, + 'type' => 'text', + 'name' => 'No default', + ) + ); $listed = $this->execute( 'list-fields', array( 'form_id' => $this->form->id ) ); - $this->assertNotWPError( $listed, 'list-fields should validate for string-keyed options and array default values.' ); + $this->assertNotWPError( $listed, 'list-fields should validate for string-keyed options, array default values and a NULL default.' ); $this->assertArrayHasKey( FrmField::getOne( $select_id )->field_key, $listed ); $this->assertArrayHasKey( FrmField::getOne( $address_id )->field_key, $listed ); + $this->assertArrayHasKey( FrmField::getOne( $text_id )->field_key, $listed ); } /** From 8f2fe8cdcf1e8292d58833795474840a4fab1425 Mon Sep 17 00:00:00 2001 From: "vivi-the-going-merry[bot]" <308115520+vivi-the-going-merry[bot]@users.noreply.github.com> Date: Mon, 26 Oct 2026 11:26:23 -0600 Subject: [PATCH 7/7] Keep numeric option types in list-fields and create-field schemas after rebase --- classes/controllers/FrmAbilitiesFieldsController.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/classes/controllers/FrmAbilitiesFieldsController.php b/classes/controllers/FrmAbilitiesFieldsController.php index dce538f75f..75d0a8faad 100644 --- a/classes/controllers/FrmAbilitiesFieldsController.php +++ b/classes/controllers/FrmAbilitiesFieldsController.php @@ -82,11 +82,11 @@ private static function register_list_fields_ability() { 'options' => array( 'type' => array( 'array', 'object' ), 'description' => __( - 'Radio, dropdown, or checkbox choices: strings, or {"label", "value"} objects when using separate values, or an object keyed by option key.', + 'Field choices: strings, numbers (star rating, scale), or {"label", "value"} objects when using separate values, or an object keyed by option key.', 'formidable' ), - 'items' => array( 'type' => array( 'string', 'object' ) ), - 'additionalProperties' => array( 'type' => array( 'string', 'object' ) ), + 'items' => array( 'type' => array( 'string', 'number', 'object' ) ), + 'additionalProperties' => array( 'type' => array( 'string', 'number', 'object' ) ), ), 'field_order' => array( 'type' => 'integer', @@ -177,10 +177,10 @@ private static function register_create_field_ability() { 'formidable' ), 'items' => array( - 'type' => array( 'string', 'object' ), + 'type' => array( 'string', 'number', 'object' ), ), 'additionalProperties' => array( - 'type' => array( 'string', 'object' ), + 'type' => array( 'string', 'number', 'object' ), ), ), 'default_value' => array(