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

Fieldtypes in config overriding "sometimes" rule with preset $rules #9507

Open
caseydwyer opened this issue Feb 11, 2024 · 1 comment
Open

Comments

@caseydwyer
Copy link
Contributor

caseydwyer commented Feb 11, 2024

Bug description

Edit: should have started with this, but I picked apart a request in my actual project just now, and realized the empty + hidden field is actually being included in the payload. Maybe that's the issue—that a hidden field is being passed through in the first place, for the custom fieldtype config? 🤔


When building out the configFieldItems in a custom field, I think any (but at minimum the numeric) fieldtypes that have an inherent/preset $rules, together with a user-defined sometimes validation rule, will always throw errors (when they're not submitted). Pretty sure the preset $rules, in this context, is overriding or taking precedence over (ie, evaluated before) the sometimes rule. From Floatval, for example:

protected $rules = ['numeric'];

Here's a repo that reproduces the issue, and a screencap of what this looks like with a bit of code + CP interface:

config-bug

How to reproduce

  1. Grab the repro-repo™
  2. Visit the Page blueprint in browser
  3. Click into the Field with Replicator Field (at the bottom)
  4. Hit Apply without making any changes (should get validation errors)
  5. Toggle on the Root Toggle
  6. See the Must be an integer. error on the Sometimes Float Field
  7. Inspect FieldWithReplicator.php, line 17, to make sure I'm not missing something obvious. 😬

Logs

No response

Environment

<details>
  <summary>Environment</summary>

Application Name: Statamic
Laravel Version: 10.43.0
PHP Version: 8.2.5
Composer Version: 2.5.4
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: statamic
Database: mysql
Logs: stack / single
Mail: smtp
Queue: sync
Session: file

Statamic
Addons: 0
Antlers: runtime
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 4.48.0 Solo
</details>

Installation

Fresh statamic/statamic site via CLI

Antlers Parser

None

Additional details

I initially thought this was related to nested fields (ie, in a Replicator)—hence that setup in the blueprint. Left it in there because it does also impact nested numerics...but it's not specific to that context, which is why I didn't emphasize it above.

Let me know if there's anything else I can do to help, here!

@afonic
Copy link

afonic commented Mar 20, 2024

Can't you just use nullable instead of sometimes if the field is in the payload?

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

No branches or pull requests

3 participants