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

Move 'date' from type IField.type to Attributes.type #65

Open
sebastianfiss-consid opened this issue Feb 5, 2024 · 5 comments
Open

Comments

@sebastianfiss-consid
Copy link

sebastianfiss-consid commented Feb 5, 2024

The 'date' in IField.type is not handled correctly. There is no component for Date, so nothing will be rendered if I specify that. Furthermore, I can't specify it as a type for the input component.

Example:

	const fields: IField[] = [
		{
			type: 'date', // wont work
			name: 'dob',
			attributes: {
				// type: 'date', // cant specify that
				id: 'dob', // required
				classes: ['form-control'],
				placeholder: 'DOB',
				autocomplete: 'off'
			},
		}
	];

...

<Formly fields={fields} {form_name} on:submit={onSubmit} />

Fix in types.ts

export interface IField {
    type: 'input' | 'textarea' | 'select' | 'checkbox' | 'radio' | 'file' | 'autocomplete'; // remove 'date'
}

export interface Attributes {
    id: string;
    type?: 'text' | 'password' | 'email' | 'number' | 'tel' | 'range' | 'date'; // add 'date'
``
@kamalkech
Copy link
Collaborator

kamalkech commented Feb 6, 2024

the date field type is an in input category so not should :

const fields = [
  {
    type: 'input', 
    name: 'dob',
    attributes: {
      type: 'date',
      id: 'dob',
      classes: ['form-control'],
      placeholder: 'DOB',
      autocomplete: 'off'
    },
  }
];

@sebastianfiss-consid
Copy link
Author

Yes, but that is not reflected in the exported types. I.e., the type definitions need to change. Currently, it is specified as a possible value for IField.type, but not as an Attribute.type.

@kamalkech
Copy link
Collaborator

the idea is to force developer respect the struct types of fields, type here:
image

which mean you don't need to mention type in attributes object, same thing with field "textarea", "select", "file" and "autocomplete", for more details check documentation here

@sebastianfiss-consid
Copy link
Author

sebastianfiss-consid commented Feb 8, 2024

I do understand your intend, I am saying that it does not work :)

See ListFieldType in your code: There is no support for a IField.type = 'date' (There is also no Date.svelte component). You already mentioned in your previous comment that "the date field type is an in input". So the types should reflect both of that, as I described in my initial issue description.

If I find the time, I'll look into creating the PR, but I did specify the Fix in the description as well.

The alternative would ofc be to have a Date.svelte component.

@kamalkech
Copy link
Collaborator

@sebastianfiss-consid i got you and i will fixe this issue soon because i will update the package for current version of svelte.
Thank you for your post and i will be happy if you share any comments or proposition to make this package more better.

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