Populate date fields with existing date if present - #140
Conversation
|
This looks like a good change. Is this project still being maintained? |
| format: toMomentDateFormat(dateFormat(fieldDescription)) | ||
| }); | ||
| input.data("DateTimePicker").date(parseDate(controller.$viewValue) || null); | ||
| if(typeof controller.$viewValue != 'undefined') { |
There was a problem hiding this comment.
@stuhol Why not just controller.$viewValue? Are null or 0 appropriate values here? Also parseDate already has protection against value absence: https://github.com/allcount/allcountjs/pull/140/files#diff-5be2946f54f08d277a71a12fdc822ba4R54
There was a problem hiding this comment.
Yep you're right probably just controller.$viewValue would be find here.
| input.data("DateTimePicker").date(parseDate(controller.$viewValue) || null); | ||
| if(typeof controller.$viewValue != 'undefined') { | ||
| input.data("DateTimePicker").date(parseDate(controller.$viewValue) || null); | ||
| input.data("DateTimePicker").defaultDate(parseDateToMoment(controller.$viewValue) || null); |
There was a problem hiding this comment.
@stuhol Could you please explain the use case of setting up defaultDate manually?
There was a problem hiding this comment.
Thanks for checking this out. To be honest it's been a long time since this commit and my memory is fuzzy. I think the use case behind setting defaultDate manually was so when a user views the calendar the stored date is already selected. When defaultDate wasn't set it would default to the current date.
| return s && moment(s, 'YYYY-MM-DD HH:mm:ss').toDate(); | ||
| } | ||
|
|
||
| function parseDateToMoment(s) { |
There was a problem hiding this comment.
@stuhol Could you please clarify why do we need parseDateToMoment (why parseDate isn't enough here)?
There was a problem hiding this comment.
While testing I found that a Date wouldn't set the defaultDate correctly. However a moment would, I didn't investigate why.
Simple change which sets the DateTimePicker defaultDate to show any existing date stored when editing date fields.