JsFormValidatorBundle icon indicating copy to clipboard operation
JsFormValidatorBundle copied to clipboard

Problem with symfony 2.6 and composer.json

Open manuelj555 opened this issue 10 years ago • 10 comments

I have the following error when execute composer require "fp/jsformvalidator-bundle":"dev-master"

Problem 1
    - Installation request for fp/jsformvalidator-bundle dev-master -> satisfiable by fp/jsformvalidator-bundle[dev-master].
    - Conclusion: remove symfony/symfony v2.6.9
    - Conclusion: don't install symfony/symfony v2.6.9
    - fp/jsformvalidator-bundle dev-master requires symfony/validator ~2.3.0,>=2.3.19||~2.4.0,>=2.4.9||~2.5.0,>=2.5.3,<=2.5.4 -> satisfiable by symfony/validator[v2.3.19, v2.3.20, v2.3.21, v2.3.22
, v2.3.23, v2.3.24, v2.3.25, v2.3.26, v2.3.27, v2.3.28, v2.3.29, v2.3.30, v2.4.10, v2.4.9, v2.5.3, v2.5.4].
    - don't install symfony/validator v2.3.19|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.20|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.21|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.22|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.23|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.24|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.25|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.26|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.27|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.28|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.29|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.3.30|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.4.10|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.4.9|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.5.3|don't install symfony/symfony v2.6.9
    - don't install symfony/validator v2.5.4|don't install symfony/symfony v2.6.9
    - Installation request for symfony/symfony == 2.6.9.0 -> satisfiable by symfony/symfony[v2.6.9].

The problem is in the symfony/validator version requirements, current 2.6 version is 2.6-dev, and the composer.json require < v2.5.4

manuelj555 avatar Jun 11 '15 20:06 manuelj555

Look here #83

66Ton99 avatar Jun 11 '15 20:06 66Ton99

what exactly is the solution for this problem? does this mean this bundle is not compatible with symfony >=2.6?

titolendable avatar Jul 06 '15 15:07 titolendable

Yes, without changes it is not compatible with Symfony >= 2.5.5

66Ton99 avatar Jul 06 '15 15:07 66Ton99

@66Ton99 not exactly what I would like to hear, such a great bundle, shame we can not use it anymore without hacking it..

titolendable avatar Jul 06 '15 15:07 titolendable

PRs with fixes with backward compatibly are welcome :)

66Ton99 avatar Jul 06 '15 16:07 66Ton99

I hacked this to work for us by changing the createElement method. We are now using the bundle successfully with 2.7 (sorry for jquery, I'm a useless js developer):

this.createElement = function (model) {
    var element = new FpJsFormElement();
    element.domNode = this.findDomElement(model);
    if (model.children instanceof Array && !model.length && !element.domNode) {
        return null;
    }

    for (var key in model) {
        if ('children' == key) {
            for (var childName in model.children) {
                var childElement = this.createElement(model.children[childName]);
                if (childElement) {
                    element.children[childName] = childElement;
                    element.children[childName].parent = element;
                }
            }
        } else if ('transformers' == key) {
            element.transformers = this.parseTransformers(model[key]);
            if(model["type"] == "choice"){
                var choices = [];
                $(element.domNode).find("input").each(function(){
                    var value = $(this).val();
                    if($.isNumeric(value)){
                        value = parseInt(value);
                    }
                    choices.push(value);
                });
                var transformer = new SymfonyComponentFormExtensionCoreDataTransformerChoicesToBooleanArrayTransformer();
                transformer.choiceList = choices;
                element.transformers.push(transformer);
            }
        } else {
            element[key] = model[key];
        }
    }

    // Parse constraints
    for (var type in element.data) {
        var constraints = [];
        if (element.data[type].constraints) {
            constraints = this.parseConstraints(element.data[type].constraints);
        }
        element.data[type].constraints = constraints;

        var getters = {};
        if (element.data[type].getters) {
            for (var getterName in element.data[type].getters) {
                getters[getterName] = this.parseConstraints(element.data[type].getters[getterName]);
            }
        }
        element.data[type].getters = getters;
    }

    this.attachElement(element);

    return element;
};

ppamment avatar Jul 07 '15 15:07 ppamment

Hi,

Is this hack compatible with previous versions as well or only starting 2.7.

Thanks.

rrajkomar avatar Jul 16 '15 14:07 rrajkomar

I'm not 100% but I can give you some information to hopefully work it out. In our case the major problem was that the symfony ChoiceType started using different view transformers as of 2.7. You can see this here:

For 2.6, line 71 it adds a ChoicesToBooleanArrayTransformer: https://github.com/symfony/symfony/blob/2.6/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

This then got propagated through into the js model and added the appropriate transformer that made the choice validation work.

For 2.7, line 144, it instead no uses a ChoicesToValuesTransformer which the javascript I believe does not implement: https://github.com/symfony/symfony/blob/2.7/src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

My hack then was just to manually readd the transformer in javascript even though it's not present in the json model and everything was well in the world again. It's not a pretty solution though, and I definitely don't think it covers every case, but fortunately it does cover all the cases we are currently using.

So my advice is check to see if your form component version is using the ChoicesToBooleanArray view transformer, and if it's not, this hack may work for you.

ppamment avatar Jul 16 '15 17:07 ppamment

I have the same problem in 2.7 with a Entity form type. The 'transformers' object remains empty in the generated js. I tried to enable this hack (from @ppamment) for Entity form types by changing it to

 if(model["type"] == "choice" || model["type"] == "entity"){

But then I keep getting the error; "The choices "2" were not found."

My radio input values are 1 and 2, which doesn't compare to the choiceList key's 0 and 1 (fp_js_validator.sj:2132)

Does someone knows how to get entity form types to work in Symfony 2.7? This is the only reason we can't update to 2.7.

Update: The 'choice-fix' branch of @usetreno 's fork fixed my problem.

ruijl avatar Jan 25 '16 12:01 ruijl

It should be fixed in #104 Can you confirm it?

66Ton99 avatar Mar 29 '16 12:03 66Ton99