[SOLVED] Date Input, default value?

Hi guys.
I’ve made a form with a Date input (native calendar) but I can’t put a correct default value to that field (I don’t care about format, I just want a default value because of data editing).
I have timestamp and date, both doesn’t work, even following the basic formatting and the suggested one by the console log.
I really don’t know how to get the work done.

If you have any idea of what to test it will be better than nothing!

Hi, Portapipe,

Try this.

<input type="date" name='birthday' value ="{{ olddate | date: 'yyyy-MM-dd'}}" id="newdate" >

I use value attribute to set the default value, and just don’t use ng-model, then I use native JavaScript get the input value in the controller.

1 Like

Dude what can I say… IT WORKS! FINALLY!
The problem is definitely the ng-model. Without it is more tricky but it works like expected.
There are a couple of other issues, so I’ve preferred to clear the field on $ionicView.enter:


THEN if the page is for data editing I set the default date value like that:

document.getElementById("newdate").value = $rootScope.formEdit.date;

and the job is done.
Why I’m doing this? Because the first time you edit the date value the value in the date input field remain the same (the first you’ve choose).
With this trick you can let the form value="" (or even don’t set it) and use these two rows in your controller to make the trick.

Thanks @Richdho! Solved!

Glad it helped :relaxed:

This works beautifully, thanks so much. I figured type=“time” would be near identical (‘hh:mm a’) but no luck. Any ideas for defaulting a time value?

SOLVED: the mask is ‘HH:mm’

1 Like