formly-js / angular-formly

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

New type setting error #738

Open marksq opened 7 years ago

marksq commented 7 years ago

Hello!

I use Ui-router, Formly and Formly Bootstrap Templates in my project and I have got the error:

image

Before this I had created the new type (as it was suggested in issue Formly Bootstrap Templates Issue #67):

formlyConfig.setType({
    name: 'select-with-empty',
    extends: 'select',
    template: '<select class="form-control" ng-model="model[options.key]"><option value=""> </option></select>',
  });

The error appears when I open a state with form (which contains 'select-with-empty' type fields), then open an other state and then open the first state again. All of 'select-with-empty' type fields are hide, count of errors equals count of 'select-with-empty' type fields.

What is wrong? May be it's a question to Formly Bootstrap Templates developers?

random-one commented 7 years ago

@marksq I had similar issue trying to override exactly the select template just to put a custom class on it, which was wrong because there is a thing called ngModelAttrs, but however I noticed that this error does not happen when I didn't override the template. Other template overrides as I saw in examples also include the <formly-transclude></formly-transclude> tag, which I assume is the one to blame to see this error because I think it has something to do with the scope.

I don't think I answered your question but I am sure I gave you a hint. Explore the formlyConfig and I am sure you will find how to add an empty element without overriding the <select> template.