Open dannycallaghan opened 9 years ago
Sorry, I don't have a lot of time to look into this. I recommend you ask on the chat: http://chat.angular-formly.com
@kentcdodds I bet you don't! (belated congratulations by the way :) )
I've asked the chat room. Thanks.
Hi @kentcdodds
Can I ask why this has been closed? Anyone coming across this, with the same issue, is going to feel that it's been fixed in an update, or they're doing something wrong. I appreciate that you're too busy to look at it at the moment, but the issue still remains.
Quick fix from me. Might help someone, but I'm painfully aware that 'datepicker' is hardcoded into the resetModel() function, so it's not at a state to be thinking about pull requests. It get's me over the line at work for the time being.
I've edited the resetModel() function to now check if the type is 'datepicker', and I do this:
function resetModel() {
if ($scope.options.type === 'datepicker') {
var format = $scope.to.datepickerOptions && $scope.to.datepickerOptions.format || 'shortDate';
$scope.model[$scope.options.key] = $filter('date')($scope.options.initialValue, format);
} else {
$scope.model[$scope.options.key] = $scope.options.initialValue;
}
// Rest of the function...
}
Ig this should be closed, now it's triggered the ResetModel()
. You may take alook at the example now https://github.com/formly-js/angular-formly-website/pull/92.
There is an issue with using the ui datepicker (and date formats / json) in formly when calling resetModel().
As you can see here, resetModel() actually removes the model for that element. This is the same when using a pre-populated model, or the 'defaultValue' property:
http://jsbin.com/vokowo/edit?html,js,output
Hitting resetModel twice actually fixes the problem - it returns the values to the model. But, of course, this isn't satisfactory as is.
Any ideas?