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

getFieldValues() default value instead of null #704

Open
rudiedirkx opened this issue Jan 25, 2023 · 2 comments
Open

getFieldValues() default value instead of null #704

rudiedirkx opened this issue Jan 25, 2023 · 2 comments

Comments

@rudiedirkx
Copy link
Collaborator

rudiedirkx commented Jan 25, 2023

Give fields and field types a default value for 'no value submitted'. getFieldValues() returns null or not at all, but that's imperfect sometimes. 0 checkboxes checked should give an empty array, not null.

class FormField {
    protected mixed $nullValue = null;
}

class CollectionType {
    protected mixed $nullValue = [];
}

$this->add('optional_hobbies', 'checkboxes', [
    'null_value' => [],
]);

or something.

@Eloar
Copy link
Contributor

Eloar commented Apr 6, 2023

there is default_value option for fields that, in theory, should act as fallback if nothing provided,

@rudiedirkx
Copy link
Collaborator Author

That's not used in getFieldValues(). That's only for building the form, not for getting the values during submission.

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