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

ui datepicker and resetModel() #79

Open
dannycallaghan opened this issue Sep 28, 2015 · 5 comments
Open

ui datepicker and resetModel() #79

dannycallaghan opened this issue Sep 28, 2015 · 5 comments

Comments

@dannycallaghan
Copy link
Contributor

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?

@kentcdodds
Copy link
Member

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

@dannycallaghan
Copy link
Contributor Author

@kentcdodds I bet you don't! (belated congratulations by the way :) )

I've asked the chat room. Thanks.

@dannycallaghan
Copy link
Contributor Author

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.

@kentcdodds kentcdodds reopened this Sep 29, 2015
@dannycallaghan
Copy link
Contributor Author

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...
}

@sukrosono
Copy link
Contributor

Ig this should be closed, now it's triggered the ResetModel(). You may take alook at the example now #92.

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

3 participants