Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constraints 'propertyPath' is not respected #148

Open
boubbin opened this issue Jul 4, 2018 · 2 comments
Open

Constraints 'propertyPath' is not respected #148

boubbin opened this issue Jul 4, 2018 · 2 comments

Comments

@boubbin
Copy link

boubbin commented Jul 4, 2018

For example this annotation

    public $start_date;
     /**
     * @Assert\GreaterThan(propertyPath = "start_date", message = "End smaller than start")
     */
    public $end_date;

Will be processed with GreaterThan like it should be:

function SymfonyComponentValidatorConstraintsGreaterThan() {
    this.message = '';
    this.value = null;

    this.validate = function (value) {

        var f = FpJsFormValidator;
        if (f.isValueEmty(value) || value > this.value) {
            return [];
        } else {
            return [
                this.message
                    .replace('{{ value }}', FpJsBaseConstraint.formatValue(value))
                    .replace('{{ compared_value }}', FpJsBaseConstraint.formatValue(this.value))
            ];
        }
    }
}

but this.value is always null here and therefor the field is never valid.

I could not find any references in the code to propertyPath but it is parsed correctly to the client side, just never used. Anyway you will never know what is the actual element in this case

@TomasLudvik
Copy link

Hey @boubbin, I have just run into same problem - have you ever managed to get it working somehow?

@boubbin
Copy link
Author

boubbin commented Aug 25, 2020

Hey @boubbin, I have just run into same problem - have you ever managed to get it working somehow?

No. I did not.

We are still using this library extensively and I haven't encountered this problem in a long time. My guess is that we only had one constraint using propertyPath.

I suggest that you look into transferring the constraint into callback constraint (if possible) since they work very nicely with the library. They are a bit more work but once you have some ground work in place they come easy. We have currently multiple dozen different callback constraints implemented client-side.

One option is also to disable the validation for this field in the client-side. You will sooner or later need this kind of mechanism anyway where you can easily just not validate some constraints.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants