formly-js / angular-formly

JavaScript powered forms for AngularJS
http://docs.angular-formly.com
MIT License
2.22k stars 405 forks source link

Invalid formatter value #682

Open Blaze34 opened 8 years ago

Blaze34 commented 8 years ago

Invalid first value in formatter with datapicker field Similar formatter with text input works fine Short example Look console logs

P.S. In this example I noticed one more bug: initial value datepicker is not formatted I got Tue May 17 2016 18:25:03 GMT+0300 (EEST) but have to 2016 I check datapicker same version without formly and it works fine (example)

I suppose formatters not calling first time when template initializing. For example input[type=number] throw error if initial value is a string

Blaze34 commented 8 years ago

Somebody fix it? I published this issue a week ago and no activity yet!

Blaze34 commented 8 years ago

Two weeks... Nobody care?

Blaze34 commented 8 years ago

Month... Support are worse that I ever met! Good idea, but bad implementation.

Blaze34 commented 8 years ago

Bug with datepicker: the reason in order of formatters. Datepicker from angular-ui add own formatter (which parse date). Angular-formly formatters add after that and get value already formatted by datepicker's formatter.

My solution is remove formatter/parser from formly and do transformation in controller I hope this will help somebody.

david-potgieter commented 7 years ago

@Blaze34 - sorry for being late to the party. I have written a provider and use that to do my parsing. In the provider I do date validation and formatting with MomentJS.

In my formly field setup:

parsers: [(value) => { return this.regexProvider.formatDate(value) }]

and then in the provider:

formatDate(value) {
        // validation checks etc...
        return this.moment(value).format('DD/MM/YYYY');
}
gillchristian commented 7 years ago

@david-potgieter thank you for sharing!

@Blaze34 this is an open source project, people dedicate their free time to contribute. You can always solve the bug yourself and submit a PR, that'd be much appreciated. Thanks!