我正在创建一个具有自定义表单类型的表单。
这是我的主要形式:
public function buildForm(FormBuilder $builder, array $options) {
$builder->add('area', new AreaSelectType($this->em, true, true, $this->organizercountry), array('selectedArea' => null,'label' => 'City'));
$builder->add('location', new LocationAutocompleteType('#steptwo_location_autocomplete', '#steptwo_location_hidden', '#steptwo_area_pkid'));
}
public function getDefaultOptions(array $options)
{
$collectionConstraint = new Collection(array(
'area' => new NotNull(array('message' => 'nicht leer')),
'location' => new NotNull(array('message' => 'nicht leer'))
));
return array('validation_constraint' => $collectionConstraint);
}
这是 LocationAutocompleteType:
public function buildForm(FormBuilder $builder, array $options) {
$builder->setAttribute('source', $options['source']);
$builder->add('autocomplete', 'text', array('label' => false, 'attr' => array('autocomplete' => 'off')));
$builder->add('hidden', 'hidden', array('label' => false, 'attr' => array('autocomplete' => 'off')));
}
public function getDefaultOptions(array $options) {
$collectionConstraint = new Collection(array(
'hidden' => new NotNull(array('message' => 'nicht leer')),
));
return array('validation_constraint' => $collectionConstraint, 'source' => 'organizer.ajax.location');
}
我所做的一切,自定义表单类型都没有经过验证。我必须怎么做才能正确验证表单类型并通过父表单中的位置属性获取错误?