0

我正在创建一个具有自定义表单类型的表单。

这是我的主要形式:

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');                                
}

我所做的一切,自定义表单类型都没有经过验证。我必须怎么做才能正确验证表单类型并通过父表单中的位置属性获取错误?

4

1 回答 1

2

getDefaultOptions主表单的方法中,您必须添加'cascade_validation' => true到返回的数组以启用对子表单的验证。这是最近的更改,尚未在文档中更新。

于 2012-05-10T04:39:49.353 回答