Hi!
The new ticket is #9751 (http://trac.symfony-project.org/ticket/9751).

A little remark about that: the choices that can be written in the 
annotation (choices or callback) are supposed to be an array of allowed 
values. In my case, most of the time, the allowed values should not be 
displayed as is to the user. So currently I'm forced to create 2 callbacks 
for each select box. An example:
public function getPrograms() {
    return array('foo1', 'foo2'); // or array_keys() on getProgramLabels()
}
public function getProgramLabels() {
    return array('foo1' => 'Foo bar 1', 'foo2' => 'Foo Bar 2');
}

I use the getPrograms() method as the validation callback and the 
getProgramLabels() method when adding the field to the form:
$builder->add('program', 'choice', array('choices' => 
MyEntity::getProgramLabels()))

I think I already talked about that before the form refactoring, and at that 
time, there was no other way to do it. I'm wondering if the situation has 
changed on this now? I'm not very comfortable with some sort of duplicated 
code (and I have many select boxes in some of my forms).
A (possibly stupid) solution could be to be able to configure in the 
annotation if the allowed values are the keys or the values of the given 
array? something like that:
/**
 * @assert:Choice(callback = "getProgramLabels", choices_source = "keys")
 */
Then the guesser would be able to guess values and descriptive text to 
display (if present).
What do you think about it?

Thanks!
Anthony

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to