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

Ability to bind date object #145

Open
bluepuma77 opened this issue Oct 18, 2023 · 9 comments
Open

Ability to bind date object #145

bluepuma77 opened this issue Oct 18, 2023 · 9 comments

Comments

@bluepuma77
Copy link

Trying to get svelty-picker to work with sveltekit-superforms and my own form input builder.

<SveltyPicker
    name={name}
    aria-invalid={$errors[name] ? "true" : undefined}
    bind:value={form[name]}
    mode="date"
    i18n={de}
    format="yyyy-mm-dd"
    manualInput={true}
    displayFormat="dd.mm.yyyy"
    inputClasses="form-control {$errors[name]?'errorField':''}"
/>

My current issue is that after submit and reload, svelty-picker breaks, I assume because the bind:value is null or undefined.

Uncaught (in promise) TypeError: (intermediate value).split is not a function
    watchExternalValueChange SveltyPicker.svelte:172
    update SveltyPicker.svelte:135
    update scheduler.js:115
    flush scheduler.js:79
    promise callback*schedule_update scheduler.js:20
    make_dirty Component.js:81
    ctx Component.js:139
    $$set root.svelte:638

Is it possible to improve this, so even if null or undefined is supplied, the date is shown empty and not breaking the component? Maybe some more checking or using try catch?

@mskocik
Copy link
Owner

mskocik commented Oct 18, 2023

This is weird, because setting value to null works correctly. I would need reproducible example.

The error from your log is probably referring to this line:

(stringValue || '').split(',')

but as you can see, null value is handled properly by replacing with empty string

@mskocik
Copy link
Owner

mskocik commented Oct 18, 2023

@bluepuma77 Are you sure you are binding string as a value?

@bluepuma77
Copy link
Author

bluepuma77 commented Oct 20, 2023

@mskocik Sorry, it's a big setup, so reproduction would take some time.

Today I got a slightly different error:

TypeError: value.split is not a function
    at Module.initProps (/Users/Develop/node_modules/svelty-picker/dist/utils/state.js:22:66)
    at /Users/Develop/node_modules/svelty-picker/dist/components/SveltyPicker.svelte:94:47
    at Object.$$render (/Users/Develop/node_modules/svelte/src/runtime/internal/ssr.js:156:16)
    at /Users/Develop/src/routes/incident/InputDate.svelte:13:54

which points to this line:

    22	  let valueArray = value ? (Array.isArray(value) ? value : value.split(',')) : [];

I think I might bind a Date instead of a String.

And when I turn it into a String, then SuperForms using its schema indicates the field as error...

@mskocik
Copy link
Owner

mskocik commented Oct 20, 2023

yes, passing the Date would explain given error. String is expected, Date objects are used internally. But they are exported on dateChange event, if that would help your use case.

@bluepuma77
Copy link
Author

@mskocik Would the current architecture allow for an extension like

<SveltyPicker
    name={name}
    bind:date={form[name]}
/>

to enable a date variable to be passed in and out?

@mskocik
Copy link
Owner

mskocik commented Oct 27, 2023

I would need to try it out, but I think it might be possible but I wouldn't recommend it due possible issues across timezones

@mskocik
Copy link
Owner

mskocik commented Nov 14, 2023

@bluepuma77 Is this still relevant for you?

@bluepuma77
Copy link
Author

For now I switched to date-picker-svelte because that uses Date and therefore works better with SuperForms.

@mskocik
Copy link
Owner

mskocik commented Nov 22, 2023

Sure, no problem. Btw to you know, you could use proxy for that?

@mskocik mskocik changed the title (intermediate value).split is not a function Ability to bind date object Nov 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants