Skip to content

Conversation

@issei-m
Copy link
Contributor

@issei-m issei-m commented Jan 23, 2016

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Documentation says, since 2.7, choice value is treated as corresponding item value (if choices_as_values option is true). Null as well.

$builder->add('attending', 'choice', array(
    'choices' => array(
        'yes' => true,
        'no' => false,
        'maybe' => null,
    ),
    'choices_as_values' => true,
));

But actually null doesn't work as expected since ArrayChoiceList::getChoicesForValues() uses isset to check whether given value exists in its choices.

It should use array_key_exists instead to do so here.

@issei-m
Copy link
Contributor Author

issei-m commented Jan 24, 2016

Sorry, I mistook target branch. So I re-create a new one.

@issei-m issei-m closed this Jan 24, 2016
fabpot added a commit that referenced this pull request Jan 27, 2016
… (issei-m)

This PR was merged into the 2.7 branch.

Discussion
----------

[Form] ArrayChoiceList can now deal with a null in choices

re-create for mistaken #17502

---

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Documentation says, since 2.7, choice value is treated as corresponding item value (if `choices_as_values` option is true). Null as well.

```php
$builder->add('attending', 'choice', array(
    'choices' => array(
        'yes' => true,
        'no' => false,
        'maybe' => null,
    ),
    'choices_as_values' => true,
));
```

But actually null doesn't work as expected since `ArrayChoiceList::getChoicesForValues()` uses `isset` to check whether given value exists in its choices.

It should use `array_key_exists` instead to do so here.

Commits
-------

68292bb [Form] ArrayChoiceList can now deal with a null in choices
@issei-m issei-m deleted the fix-choice-bug branch January 27, 2016 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants