svelte-formly
svelte-formly copied to clipboard
Move 'date' from type IField.type to Attributes.type
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'
``
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'
},
}
];
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.
the idea is to force developer respect the struct types of fields, type here:
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
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 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.