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

Error "passing 'type' property is not allowed when 'template' is set" even when template set to null #2121

Closed
rogercoder opened this issue Feb 29, 2020 · 5 comments · Fixed by #2126
Labels

Comments

@rogercoder
Copy link

rogercoder commented Feb 29, 2020

Yes! I did!

Description
A clear and concise description of what the bug is.

In ngx-formly version 4 I had been emitting field json like this:

"type":"select", 
"template":null,

This worked fine, but this was broken in commit 71d343e, where the check was previously:
if (field.template) ...
So if the template were null, everything was fine.
But in this commit the check was changed to:
if (field.hasOwnProperty('template') ...)
which is true even if the value of "template" is null.
So now I'm getting the error:
NgxFormly: passing 'type' property is not allowed when 'template' is set.
In my opinion the error is not really correct ... if "template" is null it is not actually being "set" to anything.

Is there a reason you are no longer checking to see if the template has been set?

I don't know about the larger issue you were trying to fix, but if you have no objection I could do a pull request with line 77 changed to:
(field.hasOwnProperty('template') && field.template)
Minimal Reproduction

In the stackblitz note that the text input and select question have disappeared because I set template: null for both of them:
https://stackblitz.com/edit/ngx-formly-ui-bootstrap-bsjvxi?file=src/app/app.component.ts

Your Environment

  • Angular version: 9.0.2
  • Formly version: 5.5.12

Additional context
Add any other context about the problem here.

@rogercoder
Copy link
Author

I have downgraded to 5.5.7 for the time being and the fields in my forms are showing again.

@aitboudad
Copy link
Member

is there any relevant reason that prevent you to remove entirely template instead of set it to null?

@rogercoder
Copy link
Author

The json is generated programmatically using Spring on the server side. So if the template is not set the json is generated as template: null.

The problem, starting with ngx-formly 5.5.8, is that the code no longer checks if the template is set (despite what the error message says): it now only checks to see if the template attribute exists.

In my proposed fix ngx-formly would once again check to see if the template were set.

@kenisteward
Copy link
Collaborator

kenisteward commented Mar 4, 2020 via email

@aitboudad
Copy link
Member

This issue has been fixed and released as part of v5.5.14 release.

as @kenisteward suggested It would be better to avoid passing unnecessary data 😄!

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

Successfully merging a pull request may close this issue.

3 participants