-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[3.0.2]problem with buildForm (formtype) #17791
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
Comments
Can you explain your issues a bit more and how it is even different from the referenced issue? The best would be to form the Symfony Standard Edition and make the changes needed to reproduce it. |
in ChoiceType::class, if expanded ===true ,validator return error : class SearchMediaType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options)
{
$data = [ 'size' => 'thumbnail'];/ /defalt values
$builder->setMethod('GET')
->add('tagName', SearchType::class)
->add('size', ChoiceType::class, [
'choices' => array('thumbnail' => 'thumbnail',
'low_resolution' => 'low_resolution',
'standard_resolution' => 'standard_resolution',
),
'choices_as_values' => true,
'multiple' => false,
'expanded'=> TRUE,
'empty_data' => $data['size']
]
); Size valus asserts: //searchmediaentity.php
/**
* @Assert\NotBlank()
* @Assert\NotNull()
* @Assert\Choice({"thumbnail", "low_resolution", "standard_resolution"})
*/
protected $size; if expanded ===false then all right soft info : composer.json:
{
"name": "alex1442/3.0",
"license": "proprietary",
"type": "project",
"autoload": {
"psr-4": {
"": "src/"
},
"files": [
"app/AppKernel.php"
]
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"require": {
"php": ">=5.5.9",
"symfony/symfony": "3.0.*",
"doctrine/orm": "^2.5",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/doctrine-cache-bundle": "^1.2",
"symfony/swiftmailer-bundle": "^2.3",
"symfony/monolog-bundle": "^2.8",
"sensio/distribution-bundle": "^5.0",
"sensio/framework-extra-bundle": "^3.0.2",
"incenteev/composer-parameter-handler": "^2.0",
"cosenary/instagram": "^2.3",
"hirak/prestissimo": "^0.1.7"
},
"require-dev": {
"sensio/generator-bundle": "^3.0",
"symfony/phpunit-bridge": "^3.0"
},
"scripts": {
"post-install-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
],
"post-update-cmd": [
"Incenteev\\ParameterHandler\\ScriptHandler::buildParameters",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile",
"Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget"
]
},
"extra": {
"symfony-app-dir": "app",
"symfony-bin-dir": "bin",
"symfony-var-dir": "var",
"symfony-web-dir": "web",
"symfony-tests-dir": "tests",
"symfony-assets-install": "relative",
"incenteev-parameters": {
"file": "app/config/parameters.yml"
}
}
} |
Bug confirmed in 2.7, anytime I've found a fix in if (FormUtil::isEmpty($data)) {
$data = $form->getConfig()->getEmptyData();
} Status: reviewed |
This issue comes from I don't know if we can fix them without the "hack" above in the |
Beware if you set $builder->addEventListener(FormEvents::PRE_SUBMIT, function (FormEvent $event) {
$form = $event->getForm();
$data = $event->getData();
if (FormUtil::isEmpty($data)) {
$emptyData = $form->getConfig()->getEmptyData();
if (is_callable($emptyData)) {
$emptyData = call_user_func($emptyData, $form, $data);
}
$data = (string) $emptyData;
}
// ... |
See #17822 for a cleaner fix. |
…oiceType` (HeahDude) This PR was merged into the 2.7 branch. Discussion ---------- [WIP] [2.7] [Form] fix `empty_data` option in expanded `ChoiceType` | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #17791 | License | MIT | Doc PR | - It might happen because in `Form::submit()` the handling of `empty_data` [line 597](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php#L597) comes after each child of a compound field has been submitted [line 549](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php#L549). So when `ChoiceType` is `expanded`, `compound` option is defaulted to `true` and it passes its empty submitted data to its children before handling its own `empty_data` option. This PR uses the listener already added in `ChoiceType` only when `expanded` is true to handle `empty_data` at `PRE_SUBMIT` [line 539](https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Form/Form.php#L539). - [ ] Fix FQCN in tests for 2.8 - [ ] Remove `choices_as_values` in tests for 3.0 Commits ------- d479adf [Form] fix `empty_data` option in expanded `ChoiceType`
in ChoiceType::class
if expanded set to
true
thenparameter 'empty_data' ignored ,
validator return error not null for this value
a similar problem #17789
sf 3.0.2
The text was updated successfully, but these errors were encountered: