svelte-formly icon indicating copy to clipboard operation
svelte-formly copied to clipboard

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

Open sebastianfiss-consid opened this issue 1 year ago • 5 comments

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'
``

sebastianfiss-consid avatar Feb 05 '24 10:02 sebastianfiss-consid

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

kamalkech avatar Feb 06 '24 23:02 kamalkech

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.

sebastianfiss-consid avatar Feb 07 '24 05:02 sebastianfiss-consid

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

kamalkech avatar Feb 07 '24 22:02 kamalkech

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.

sebastianfiss-consid avatar Feb 08 '24 05:02 sebastianfiss-consid

@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.

kamalkech avatar Feb 13 '24 17:02 kamalkech