Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x]: Omitting a dropdown field's value which has a default doesn't validate #15706

Closed
boboldehampsink opened this issue Sep 10, 2024 · 7 comments
Assignees
Labels

Comments

@boboldehampsink
Copy link
Contributor

What happened?

Description

Since 5.4, when omitting a field's value which has a default, it doesn't validate anymore. This worked up until 5.3.

Steps to reproduce

  1. Create a dropdown field with a default value
  2. Add to an entry type
  3. Create a new entry (programmatically, we use it in fixtures) that omits setting this field

Expected behavior

Validation should pass, as it should use the default value

Actual behavior

Validation fails

Craft CMS version

5.4.2

PHP version

8.3

Operating system and version

No response

Database type and version

No response

Image driver and version

No response

Installed plugins and versions

@i-just
Copy link
Contributor

i-just commented Sep 10, 2024

Hi, thanks for getting in touch! I’m having trouble replicating this. Could you please share a screenshot of the dropdown field’s settings and an associated stack trace?

@boboldehampsink
Copy link
Contributor Author

This is the dropdown:

columnSuffix: null
handle: seoMetaRobots
instructions: null
name: 'Meta robots'
searchable: false
settings:
  options:
    -
      __assoc__:
        -
          - label
          - 'index, follow'
        -
          - value
          - 'index, follow'
        -
          - default
          - '1'
    -
      __assoc__:
        -
          - label
          - 'noindex, follow'
        -
          - value
          - 'noindex, follow'
        -
          - default
          - ''
    -
      __assoc__:
        -
          - label
          - 'index, nofollow'
        -
          - value
          - 'index, nofollow'
        -
          - default
          - ''
    -
      __assoc__:
        -
          - label
          - 'noindex, nofollow'
        -
          - value
          - 'noindex, nofollow'
        -
          - default
          - ''
translationKeyFormat: null
translationMethod: none
type: craft\fields\Dropdown

This is the error the fixtures now throw (since 5.4):

web-1  | Exception 'craft\errors\InvalidElementException' with message 'Meta robots is invalid.'
web-1  | 
web-1  | in /app/user/vendor/craftcms/cms/src/test/fixtures/elements/BaseContentFixture.php:85
web-1  | 
web-1  | Stack trace:
web-1  | #0 /app/user/vendor/yiisoft/yii2/test/FixtureTrait.php(96): craft\test\fixtures\elements\BaseContentFixture->load()
web-1  | #1 /app/user/vendor/yiisoft/yii2/console/controllers/FixtureController.php(160): yii\console\controllers\FixtureController->loadFixtures(Array)
web-1  | #2 [internal function]: yii\console\controllers\FixtureController->actionLoad(Array)
web-1  | #3 /app/user/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
web-1  | #4 /app/user/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
web-1  | #5 /app/user/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('load', Array)
web-1  | #6 /app/user/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('load', Array)
web-1  | #7 /app/user/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\FixtureController->runAction('load', Array)
web-1  | #8 /app/user/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('fixture/load', Array)
web-1  | #9 /app/user/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('fixture/load', Array)
web-1  | #10 /app/user/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('fixture/load', Array)
web-1  | #11 /app/user/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
web-1  | #12 /app/user/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
web-1  | #13 /app/user/craft(20): yii\base\Application->run()
web-1  | #14 {main}
web-1  | 2024-09-10 15:23:59 [console.INFO] [craft\services\Elements::_saveElementInternal] Element not saved due to validation error: Array
web-1  | (
web-1  |     [seoMetaRobots] => Array
web-1  |         (
web-1  |             [0] => Meta robots is invalid.
web-1  |         )
web-1  | 
web-1  | )
web-1  |  {"memory":46898984} 
web-1  | 2024-09-10 15:23:59 [console.ERROR] [craft\errors\InvalidElementException] craft\errors\InvalidElementException: Meta robots is invalid. in /app/user/vendor/craftcms/cms/src/test/fixtures/elements/BaseContentFixture.php:85
web-1  | Stack trace:
web-1  | #0 /app/user/vendor/yiisoft/yii2/test/FixtureTrait.php(96): craft\test\fixtures\elements\BaseContentFixture->load()
web-1  | #1 /app/user/vendor/yiisoft/yii2/console/controllers/FixtureController.php(160): yii\console\controllers\FixtureController->loadFixtures(Array)
web-1  | #2 [internal function]: yii\console\controllers\FixtureController->actionLoad(Array)
web-1  | #3 /app/user/vendor/yiisoft/yii2/base/InlineAction.php(57): call_user_func_array(Array, Array)
web-1  | #4 /app/user/vendor/yiisoft/yii2/base/Controller.php(178): yii\base\InlineAction->runWithParams(Array)
web-1  | #5 /app/user/vendor/yiisoft/yii2/console/Controller.php(180): yii\base\Controller->runAction('load', Array)
web-1  | #6 /app/user/vendor/craftcms/cms/src/console/ControllerTrait.php(89): yii\console\Controller->runAction('load', Array)
web-1  | #7 /app/user/vendor/yiisoft/yii2/base/Module.php(552): craft\console\controllers\FixtureController->runAction('load', Array)
web-1  | #8 /app/user/vendor/yiisoft/yii2/console/Application.php(180): yii\base\Module->runAction('fixture/load', Array)
web-1  | #9 /app/user/vendor/craftcms/cms/src/console/Application.php(91): yii\console\Application->runAction('fixture/load', Array)
web-1  | #10 /app/user/vendor/yiisoft/yii2/console/Application.php(147): craft\console\Application->runAction('fixture/load', Array)
web-1  | #11 /app/user/vendor/craftcms/cms/src/console/Application.php(122): yii\console\Application->handleRequest(Object(craft\console\Request))
web-1  | #12 /app/user/vendor/yiisoft/yii2/base/Application.php(384): craft\console\Application->handleRequest(Object(craft\console\Request))
web-1  | #13 /app/user/craft(20): yii\base\Application->run()
web-1  | #14 {main} {"memory":46641376,"exception":"[object] (craft\\errors\\InvalidElementException(code: 0): Meta robots is invalid. at /app/user/vendor/craftcms/cms/src/test/fixtures/elements/BaseContentFixture.php:85)"} 

@i-just
Copy link
Contributor

i-just commented Sep 11, 2024

Thanks! I’m still unable to reproduce this. Any chance you could send over a project where this is happening ([email protected])?

@DowleyDeveloped
Copy link

Am also getting this on my project. Seems to be when using the slideout for entry types. The validation fails each time if the dropdown hasn't been changed from the default value

@iwingate-digistorm
Copy link

iwingate-digistorm commented Sep 13, 2024

I was just about to create a ticket for this! None of the default field values for dropdown & radio fields have been saving.

I'm only having this issue for nested matrix fields (Card view mode)

How to replicate:

  1. add a new entry to a nested matrix
  2. save the entry in the slideout without editing the default values
  3. re-open the newly created entry, the radio & dropdown fields with default values should be empty

@i-just
Copy link
Contributor

i-just commented Sep 13, 2024

Thanks for the additional info! I think I can reproduce this now.

@brandonkelly
Copy link
Member

Craft 5.4.4 is out with this fix. Thanks again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants