Dynamic Format on Date Picker

After some teething problems with Date Picker element, I am absolutely loving it. However, there is one issue I wish I could solve with dmx-bind that refuses to work, and that is format.

I’d love to be able to dynamically bind the format stored in the database with the date picker for localization reasons. I have tried the momentjs localizations, however, instead of L returning an Australian date format (DD/MM/YYYY), it always returns (MM/DD/YYYY).

While dmx-bind is the saving grace in half of what I do, this is the first time I haven’t been able to dynamically assign a value to an element. I assume this is because momentjs is handling the formatting server side and removing the format attribute before DMX gets to bind?

Cheers
Michael

I just tested this and moment with localizations works fine.
Set the moment to English (Australia)

And format of the date picker to L:

This returns the correct date in dd/mm/yyyy format

Thanks @Teodor, did not realise that would work with a moment component. However, it still leaves the issue of being able to have this dynamically localized to the users settings.

You can use dynamic values in the moment component. For example this:

 <dmx-moment id="moment1" dmx-bind:locale="en-us"></dmx-moment>

becomes

<dmx-moment id="moment1" dmx-bind:locale="your.dynamic.value"></dmx-moment>

Good to know that we can bind to the moment component, and I’ll definitely be keeping the one I just created, however, I would like to be able to allow users to select their preferred date format.

For example, some businesses may want the standard format for their locale, but others, and myself included, may want to use dd MMM yyyy or dd MMMM yyyy for readability purposes. I know in my business (which I am initially creating this CRM for) many mistakes are made because when it’s busy, dates in the standard format are not correctly read, leading to issues in the future.

I just tested: dmx-bind:format="dynamic.value" and it seems to work fine.

1 Like

I have to admit, I have no idea what has just happened. But I have done exactly the same thing as last time and it is now working correctly. It’s the exact same string as before

dmx-bind:format="appSettings.localization_dateformat.uppercase()"

Nevermind now. Request no longer needed. I am stumped at why this wasn’t working before. But they do say, you take the car to the mechanic and the knock stops before it gets there.

Thanks for your help, @Teodor

1 Like