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

Disabled fields are submitted and saved #1279

Open
goldmont opened this issue Jan 4, 2025 · 6 comments
Open

Disabled fields are submitted and saved #1279

goldmont opened this issue Jan 4, 2025 · 6 comments
Milestone

Comments

@goldmont
Copy link
Contributor

goldmont commented Jan 4, 2025

Winter CMS Build

1.2

PHP Version

8.1

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

Hi there,

I have a switch field named is_activated in the User form that gets disabled once the user is activated. In my User model, I also have a default value for the attribute is_activated:

public $attributes = [
	'is_banned' => false,
	'is_activated' => false,
	'ldap_authenticated' => false,
];

However, for some reason, when I submit the form (context is always update) the disabled switch is submitted too and the value false is saved for the field is_activated. Thus the user is not activated anymore.

Request payload:
Image

How can I solve? Thanks.

Steps to replicate

  1. Add a switch field.
  2. Disable it somehow.
  3. Submit.

Workaround

The solution, for now, seems to be to not disable form fields.

@LukeTowers LukeTowers added this to the 1.2.8 milestone Jan 21, 2025
@LukeTowers
Copy link
Member

@goldmont what exactly are you expecting to happen?

@LukeTowers LukeTowers modified the milestones: 1.2.8, 1.2.9 Feb 26, 2025
@goldmont
Copy link
Contributor Author

@goldmont what exactly are you expecting to happen?

Hi,

I expect the default attributes to be overridden when the record exists. Furthermore, I expect the already existing attribute value to be saved again.

For example, is_activated field by default is false. When a user activates his account, the I set this attribute to true and I disable the form field. Winter is not taking into account the database value but the default one defined into the $attributes array.

@LukeTowers
Copy link
Member

@goldmont I don't think the attributes array supports being overridden like that to specify a default value. Why aren't you using the default property on the field configuration?

@goldmont
Copy link
Contributor Author

I didn't mean to change the value inside the $attributes but to consider the record value (when there's any) before saving the model.

However, I prefer the $attributes array other than the default property because I use enums too.

@LukeTowers
Copy link
Member

Hmm, I see that method of setting default values is the supported way to do it in Laravel: https://stackoverflow.com/a/39912500.

When you have is_activated true and you disable the switch, is that switch visually appearing as toggled on or off?

@goldmont
Copy link
Contributor Author

Hmm, I see that method of setting default values is the supported way to do it in Laravel: https://stackoverflow.com/a/39912500.

When you have is_activated true and you disable the switch, is that switch visually appearing as toggled on or off?

Yes, it's toggled. After saving, it turns off.

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

No branches or pull requests

2 participants