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

Custom Validators with Production build are not working : TypeError: v is not a function #424

Closed
rahul-winner opened this issue Jun 29, 2017 · 8 comments

Comments

@rahul-winner
Copy link

rahul-winner commented Jun 29, 2017

@udos86

I've already raised the issue #417. After your suggestion I'm able to work my custom validator. However, now I'm facing problem with production build which is reported with #271

I've also tried your workaround/solution [ref : commit] by having a property with same function name, however it also didn't work. With this, I got error : TypeError: v is not a function

Could you please help me out and suggest me what should be the definition of validator so that it can work in both environments dev as well prod.

Thanks a lot !
Rahul

@udos86
Copy link
Owner

udos86 commented Jun 29, 2017

@rahul-winner

As described in chapter on Custom Validators you should exclude validator function names from mangling.

@udos86 udos86 added the core label Jun 29, 2017
@rahul-winner
Copy link
Author

Thanks @udos86

We are using Angular CLI in our project. To exclude a file from mangling in Angular CLI setup, we will need to eject and then customize the webpack.config. As per discussion within, we kept it as last choice.

Do you think if there could be any other way?

I'll also try by extending FormService and probably let you know.

Also, in following up to this #417 issue, could you please why custom validator does not work when we provide 'null' against it in model.

Thanks a lot !

@rahul-winner
Copy link
Author

@udos86

I am able to make it work by extending the DynamicFormService and overriding the 'getCustomValidatorFn' method, and then passing on my custom validator function. Look at this.

What is your opinion?

image

I believe you should device some solution to this problem so that people can use custom validators even with production build. Production build is very much obvious and not everyone be comfotable with ejecting Angular CLI config to configure webpack.

One simple solution could be to let people override the method 'getCustomValidatorFn' (or you may have any other method name) and provide their own function.

Thanks. Rahul

@udos86
Copy link
Owner

udos86 commented Jun 30, 2017

@rahul-winner Thanks for your proposal!

I'm aware of CLI's lack of custom mangling options (see angular/angular-cli#5192).

All in all it's not that easy. In order to provide JSON export/import and easy declaration a validator has to be referenced by it's function name. It's the only property that a validator can be safely identified by. When mangled this information is irretrievably lost.

I'll make this a high priority issue but I can't promise a flawless solution on this.

@udos86
Copy link
Owner

udos86 commented Jun 30, 2017

@rahul-winner

Ok, so my favorite approach to this so far would be to provide an alternate syntax for defining validators on a dynamic form model like this:

customValidator: {
   name: customValidator.name,
   param: null
}

@udos86
Copy link
Owner

udos86 commented Jul 1, 2017

@rahul-winner

Ok, implementation's ready now and will be released this weekend!

Please have a look at updated docs.

@rahul-winner
Copy link
Author

Thanks ton @udos86 .. Waiting for it.

@udos86 udos86 closed this as completed in a20e766 Jul 2, 2017
@rahul-winner
Copy link
Author

Thanks a ton @udos86
I've updated to 1.4.17 and now custom validators worked like charm..

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

No branches or pull requests

2 participants