简体   繁体   中英

Symfony2 form entity add other options

I have an entity field, with basic settings, (class and property), and i'd like to add another option like "value not in list", so if is selected, i can trigger something in javascript.

->add('patrol', 'entity', array(

                'class'         => 'InterneStructureBundle:Patrol',
                'property'      => 'name',
                'empty_value'   => 'Choose',
            ))

I didnt find anything appart from "empty_value" which doesnt suits me because you cant trigger anything from it, and choices doesnt seems to work with entity..

Are there any ways to do it ?

You need to add required => false if you want to see empty value:

->add('patrol', 'entity', array(
            'class'         => 'InterneStructureBundle:Patrol',
            'property'      => 'name',
            'required'      => FALSE,
            'empty_value'   => 'Choose',
        ))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM