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
feat(json-schema): adding types #2056
base: v5
Are you sure you want to change the base?
Conversation
Deploy preview for formly-dev ready! Built with commit 8545ea6 |
@@ -426,6 +428,10 @@ export class FormlyJsonschema { | |||
} | |||
} | |||
|
|||
if (type === 'string' && format !== undefined) { | |||
return format; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should restrict this to the date & time only and check if the type is defined else we should fallback to the Native type by setting type
to the templateOptions
:
{
type: 'string',
templateOptions: {
type: 'date', // 'time' | 'datetime',
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So would changing the implementation to something like this be sufficient?
if (type === 'string' && (format === 'date' || format === 'time')) {
return format;
}
I don't quite understand your point about the templateOptions
. Should they be changed as well?
|
fefbb9b
to
56705dc
Compare
This feature is important to me. Anything I can do to help progress this PR? |
@aitboudad I'll restart this PR since the original author does not have applied the suggested changes, ok? |
What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
This PR expands the returned types by adding
date
andtime
type formats.What is the current behavior? (You can also link to an open issue here)
If your JSON Schema defines a property like
{ "type": "string", "format": "time" }
, then Formly returns the type "string" only.This means that you don't know if the returned property is supposed to be displayed as a regular input field (current standard behaviour), a time field or a date field.
What is the new behavior (if this is a feature change)?
Formly now additionally returns the types
time
ordate
if the JSON Schema provides properties with the formatstime
ordate
respectively.According to the latest JSON Schema draft an extension of the instance type is possible:
Please check if the PR fulfills these requirements
npm run build
produced a successful build. (Unit testing can be done by runningnpm test
;)npm run lint
to do this.npm run build
will fail if there are files not linted.)Other information:
In case this is classified as a breaking change you could add a flag like "extended instance types" that makes it possible to return
string
,time
anddate
instead of onlystring
?