formly-js / angular-formly

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

templateOptions.type === 'number' clears value on options.resetModel() #587

Open admwx7 opened 8 years ago

admwx7 commented 8 years ago

Given field

{
  className: 'col-xs-4',
  key: 'address.zip',
  type: 'input',
  templateOptions: {
    label: 'Zip Code',
    maxlength: 5,
    minlength: 5,
    required: true,
    type: 'number'
  }
}

when running options.resetModel(), with updated defaultValue, on the form the value of model.address.zip gets cleared, if I then run options.resetModel() again it is repopulated with the default value as expected, it's working as a toggled value essentially, however the viewValue is always correct. If I update the viewValue it will repopulate the model value correctly from that point on to match. If I remove the type: 'number' there is no issue, aside from the fact it's no longer validating that the entry is a number...

benoror commented 8 years ago

This looks related to: https://github.com/formly-js/angular-formly/issues/586

Do you mind creating an example? Please follow the instructions here: http://help.angular-formly.com

admwx7 commented 8 years ago

Turns out it's actually the maxlength field that's causing this issue, not type: 'number'

http://jsbin.com/cukerebuni/edit?html,js,output

benoror commented 8 years ago

This is weird, feel free to investigate further and submit a PR if you find the issue.