Tabs makes my form $dirty
I have a form divided by tabs, like this
<form name="form.myform" class="form-horizontal"
ng-submit="save()">
<div bs-tabs ng-model="selectedTab">
<div data-title="Common" bs-pane>
//some inputs
</div>
<div data-title="Extra" bs-pane>
//some another inputs
</div>
</div>
<div class="pull-right">
<button type="button" class="btn btn-default" ng-click="close()">Close</button>
<input type="submit" class="btn btn-default" ng-class="{'btn-success': form.myform.$dirty}" value="Save changes" />
</div>
</form>
I track form.$dirty property to show message for user about unsaved changes
Without ng-model on tabs all working good, but when I had added it, form remains $dirty forever.
What do I do? I think, that is bad idea to bind active tab to model, because it is not actual change which should be saved on server.
Made a plunker from your code: http://plnkr.co/edit/uVpUwgXluj0RhMSdhEoa?p=preview
I think the way to go would be to find a way for form to ignore tab ngModel changes.
@vmlf01 thanks for the plunker, it clarifies situation.
It is impossible to make a form which ignores some models, because model controller gets access to form directly through the DOM, as seen in angular source.
So I don't see an opportunity to influence on this process, bind active tab through optional two-way binding =? would be easier.
Maybe I can't notice some issues with it. If so, I would be glad to know it.
I see what you mean, Angular uses ngModel to keep track of form elements involved in validation and not the element type, as I initially though.
So I agree with you, the selected tab should be changed to a regular attribute binding, but that would be a breaking change, (@mgcrea) so maybe we can keep the ngModel binding but deprecate it and create a new attribute binding that has the same behavior.
That way we can keep compatibility with existing code and start migrating to new attribute?
@vmlf01 it is good idea!
If user will use ng-model attribute, it would work as it was, but he will get a warning about deprecation. Then if someone use binding by new attribute, he just will enjoy new behaviour
Landed in 7bbf6cb.
Thanks!
I have the same issue with collapse. There is already an open issue at https://github.com/mgcrea/angular-strap/issues/1561 but with no answer. It would be great a similar solution.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.