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

Add name prop #44

Open
davidh10 opened this issue Jan 11, 2023 · 4 comments
Open

Add name prop #44

davidh10 opened this issue Jan 11, 2023 · 4 comments

Comments

@davidh10
Copy link

I´m using your datepicker and it's really awesome. However, one thing I dont understand is how to put the datepicker in a form and set a name for it so it will be passed together with a form submit? Right now i created a normal input field that i hide with css and just bind that value together with the datepickers value but it would for sure be cool to just be able to add a name attribute to the Datepicker itself? Is it possible to do already or?

@probablykasper
Copy link
Owner

It's been brought up a few times. I think the way it would have to be implemented is to create a fake input element with the name attribute. My biggest question is what format the date should be in. Unix timestamp makes sense for POST requests, but something readable might be preferable for GET requests.

@davidh10
Copy link
Author

Can't it just use the time format already chosen? Personally I always use yyyy-MM-dd as it's also the format och default html date inputs :)

My current solution look like this, works fine but feels a bit meh :P

<script lang="ts">
	import { DateInput } from 'date-picker-svelte'
	let date = new Date()
	export let name: string

	$: newDate = date?.toLocaleString('sv', { timeZone: 'Europe/Stockholm' }).slice(0, 10)
</script>

<input type="text" id="dateFrom" {name} bind:value={newDate} style="display:none" />
<DateInput bind:value={date} format="yyyy-MM-dd" closeOnSelection={true} placeholder={''} />

@probablykasper
Copy link
Owner

I'd want to support it for the DatePicker component as well, which doesn't have a format. It could also cause bugs when someone uses locale-specific formats, or decides to switch the format.

Some people might want to include the hours/minutes/seconds/milliseconds too. I'm leaning towards using unix timestamps, and having people create custom input elements if they need a different format

@matthewt-assurity
Copy link

I've had a read through the linked issues. It looks like some standard HTML attributes can be passed in, but still not yet the name attribute?

This would be an awesome feature to implement, as I'd like to be able to use it with Svelte form actions (which needs the name attribute as far as I understand).

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

3 participants