JsFormValidatorBundle icon indicating copy to clipboard operation
JsFormValidatorBundle copied to clipboard

Invalid ErrorPathElement

Open manuelj555 opened this issue 10 years ago • 1 comments

The Problem

I have the following form:

class ManoDeObraForm extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
                ..
                ->add('materiales', 'collection', array(
                    'type' => new ManoDeObraMaterialType(),
                    'allow_add' => true,
                    'allow_delete' => true,
                )) ;
    }
}

The Collection item form is:

class ManoDeObraMaterialType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder
                ->add('material', 'entity', array(
                    ...
                    'error_bubbling' => true, // Important
                ))
                ->add('cantidad', 'text', array(
                    'error_bubbling' => true, // Important
                ));
    }

    public function setDefaultOptions(OptionsResolverInterface $resolver)
    {
        $resolver->setDefaults(array(
            'error_bubbling' => false, // Important
        ));
    }

The result expected is like:

2015-02-22 00_01_09- sistema de presupuestos de trabajo

But it is showing:

2015-02-22 00_07_12- sistema de presupuestos de trabajo

This is because the method FpJsFormValidator.getErrorPathElement in javascript call internally to FpJsFormValidator.getRootElement if element.bubbling is set to true, and getRootElement return the root element of validation form object.

Solution

Replace:

    this.getErrorPathElement = function (element) {
        if (!element.bubbling) {
            return element;
        } else {
            return this.getRootElement(element);
        }
    };

For

    this.getErrorPathElement = function (element) {
        if (element.bubbling && element.parent) {
            return this.getErrorPathElement(element.parent);
        } else {
            return element;
        }
    };

manuelj555 avatar Feb 22 '15 04:02 manuelj555

Ping @jumale

manuelj555 avatar Feb 22 '15 05:02 manuelj555