0

i'm creating a form with ancustom form type.

This is my mainform:

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

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

Evertything i do, the custom Formtype is not validated. What must i do to validate the form type correctly and get the Error via the Location Attribute in the parent Form ?

1 Answer 1

2

In getDefaultOptions method of main form you have to add 'cascade_validation' => true to to returned array to enable validation on child forms. It is a recent change that hasn't been updated in documentation yet.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.