php - Symfony2: Change dropdown values based on another field value -
i'm using symfony 2.3
i have form, in user selects state , city(both dropdowns).
it works expected, live show cities based on selected state user. form works this:
page 1: user selects state
page 2: user selects city (in point, state field locked, , cannot changed. user can change cities)
so how can database state value, , use on page 2 display cities of state, without using ajax.
state form:
->add('state', 'entity', array( "label" => 'name of state(*): ', 'class' => 'principalbundle:state', "attr" => array('class' => 'control-group', 'style' => 'width: 50%', 'rows' => '1'), "property"=>"statename"))
here's city form:
->add('city', 'entity', array( "label" => 'city name (*): ', 'class' => 'principalbundle:cities', "attr" => array('class' => 'control-group', 'style' => 'width: 50%', 'rows' => '1'), "property"=>"cityname"))
i cannot use event listener. tried follow docs, got error:
the 'choices_as_values' not declared
i think due version of symfony. cannot upgrade version either, @ least not yet.
you can use event listener. seems error regarding choices_as_values
. introduced in 2.7 mimic how choices
used work. in symfony 2.7 keys/values flipped how choices
array works, added choices_as_values
backwards compatibility (you set true
function in old way).
all need remove choices_as_values
setting , should go. make sure keys item value , values should display user.
$builder->add('gender', 'choice', array( 'choices' => array('m' => 'male', 'f' => 'female'), ));
$builder->add('genre', 'choice', array( 'choices' => array('m' => 'male', 'f' => 'female'), 'choices_as_values' => false, ));
also equivalent in symfony 2.7:
$builder->add('genre', 'choice', array( 'choices' => array('male' => 'm', 'female' => 'f'), 'choices_as_values' => true, ));
$builder->add('genre', 'choice', array( 'choices' => array('male' => 'm', 'female' => 'f'), 'choices_as_values' => true, ));
Comments
Post a Comment