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

Start with an empty input field #199

Closed
StuartBAutotrader opened this issue Nov 4, 2015 · 14 comments
Closed

Start with an empty input field #199

StuartBAutotrader opened this issue Nov 4, 2015 · 14 comments

Comments

@StuartBAutotrader
Copy link

Hi, Is there any way to start with an empty input field (not date pre-set), my field is not required and I would like a blank/empty input field to start with.

@DanTalash
Copy link
Contributor

  • Edit this line of the date-picker and replace the return statement to return the text you want to see. Eg, return ''; would result in an empty string.
  • Pass an invalid date into the picker (such as false). The date will be displayed as whatever text you edited the above line to return.

@johannesjo has suggested a much better option below, which does not require making changes to the lib.

@johannesjo
Copy link

Had the same problem. You could also use a decorator:

angular.module('yourModule')
    .config(function ($provide)
    {
        $provide.decorator('mFormatFilter', function ()
        {
            return function newFilter(m, format, tz)
            {
                if (!(moment.isMoment(m))) {
                    return '';
                }
                return tz ? moment.tz(m, tz).format(format) : m.format(format);
            };
        });
    });

@StuartBAutotrader
Copy link
Author

Thanks guys I will give this a try.

@StuartBAutotrader
Copy link
Author

Great fix, decorator is a fantastic way of working. Thanks for your help.

@johannesjo
Copy link

@DanTalash Thanks for sharing the correct line of code :)

@mahmutduva
Copy link

Hi this solutions when i want empty input but when i receive string date from service, input will be empty. For example when service give me '2016-02-03' string date, input field will be empty.
@johannesjo
@DanTalash

@luisantruiz
Copy link

Hi guys, I was looking for how to implement this decorator, do you have a plunker example? It's because in my case it's not working as expected. Thanks in advance.

@Dr1Ku
Copy link

Dr1Ku commented Aug 1, 2016

Would be fixed by PR https://github.com/g00fy-/angular-datepicker/pull/293

@KlassJ
Copy link

KlassJ commented Sep 20, 2016

Had the same problem. You could also use a decorator:

It's a great one but

instead of
return tz ? moment.tz(m, tz).format(format) : m.format(format);

Use (the first one return blank if tz is undefined)
return tz ? moment.tz(m, tz).format(format) : moment(m).format(format);

@chinmay235
Copy link

chinmay235 commented Jan 27, 2017

@johannesjo after I add your code I am getting this errror message -

Error: [$injector:modulerr] Failed to instantiate module myModule due to:
[$injector:unpr] Unknown provider: mFormatFilterProvider

@johannesjo
Copy link

@chinmay they probably changed it in some way or the other. I'm afraid that you will have to check their code where and if to apply the decorator.

@chinmay235
Copy link

chinmay235 commented Feb 2, 2017

thanks @johannesjo
Now This is working fine. Here is my code : https://angularjscript.github.io/angularjs-datepicker/chinu.html

I have faced another issue. can you please see above link. When I will select any date each time I am getting previous date from the input date. I select 2017-02-15 I am getting "due_date": "2017-02-14T19:00:00.000Z" in my controller. Can you please fix it

@johannesjo
Copy link

@chinmay: you probably want to open a new issue.

@chinmay235
Copy link

chinmay235 commented Feb 2, 2017

@johannesjo I have opened a new issue. Please go https://github.com/g00fy-/angular-datepicker/issues/320

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

8 participants