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

feat(json-schema): adding types #2056

Open
wants to merge 1 commit into
base: v5
Choose a base branch
from

Conversation

cndMarcel
Copy link

@cndMarcel cndMarcel commented Jan 29, 2020

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

This PR expands the returned types by adding date and time 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 or date if the JSON Schema provides properties with the formats time or date respectively.

According to the latest JSON Schema draft an extension of the instance type is possible:

"Note that JSON Schema vocabularies are free to define their own extended type system."
https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.4.2.1

Please check if the PR fulfills these requirements

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 and date instead of only string?

@netlify
Copy link

netlify bot commented Jan 29, 2020

Deploy preview for formly-dev ready!

Built with commit 8545ea6

https://deploy-preview-2056--formly-dev.netlify.com

@@ -426,6 +428,10 @@ export class FormlyJsonschema {
}
}

if (type === 'string' && format !== undefined) {
return format;
Copy link
Member

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',
  }
}

Copy link
Author

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?

@aitboudad
Copy link
Member

Note: Just in case you don't know/ or want this feature asap, a map options can be used to adjust the generated FormlyFieldConfig #1982 (comment).

@indiealexh
Copy link

This feature is important to me. Anything I can do to help progress this PR?

@aitboudad
Copy link
Member

@indiealexh see #2222 (comment)

@menosprezzi
Copy link

menosprezzi commented Sep 19, 2023

@aitboudad I'll restart this PR since the original author does not have applied the suggested changes, ok?

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

Successfully merging this pull request may close these issues.

None yet

4 participants