ember-cli-bootstrap-datepicker icon indicating copy to clipboard operation
ember-cli-bootstrap-datepicker copied to clipboard

There is no string only value

Open stonetwig opened this issue 8 years ago • 6 comments

Hey,

nice plugin!

I've noticed while using it that the value is represented as a date object which is kind of troubling when binding it to a query param (since it will basically print out the ugly version in the url bar). Is there any way to make it be string only instead of a date object?

Example in the url: somedate=Tue%20Mar%2001%202016%2000%3A00%3A00%20GMT%2B0100%20(W.%20Europe%20Standard%20Time)

Can I solve my issue? I'm thinking of maybe creating like a wrapper component, but it's modifying a value in my controller directly which can be a bit troubling.

stonetwig avatar Mar 03 '16 15:03 stonetwig

Hey @stonetwig! Because you have a Date object, it's up to you how to transform it into string of any format.

Example:

var today = new Date();
today.toISOString(); // => "2016-03-04T09:20:49.447Z"

Using other methods of Date object you could extract year, day, hours, and etc.

Query param could be bound to a Date object not directly, so then you have freedom to transform it into string of required format, and also convert a string of query param into a Date object.

soulim avatar Mar 04 '16 09:03 soulim

Hello @soulim and thanks for the response,

While I am aware how to format a date object and that I don't need to bind it directly, I kind of have to in my application since loading a specific page must fill the form out. I am unaware of when to format it since ember updates the query param automatically when I change the value in the form and it just casts the object to a string.

stonetwig avatar Mar 04 '16 09:03 stonetwig

Would it work for you, if you create a "proxy" property? The one that stands between query param and the Date object.

soulim avatar Mar 04 '16 13:03 soulim

I need this available too.. it should be an option to have it as a string instead of date object.

IntellectProductions avatar Mar 25 '16 17:03 IntellectProductions

I'd definitely call this a bug, the value passed to the bound property should match the value in the text field, ie: if the format param is set to yyyy-mm-dd then the bound property should be a string in that format, rather than a date object.

I appreciate for backwards compatibility this should probably be an opt-in setting, at least until v1.0

mattbearman avatar Apr 07 '16 15:04 mattbearman

@soulim Maybe with an ember computed value or something, but it feels like it creates a lot of unnecessary complexity for me. As of now I am just using normal input fields instead.

stonetwig avatar Apr 22 '16 12:04 stonetwig