angular-strap icon indicating copy to clipboard operation
angular-strap copied to clipboard

Tabs makes my form $dirty

Open just-boris opened this issue 12 years ago • 8 comments

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.

just-boris avatar Nov 05 '14 13:11 just-boris

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 avatar Nov 05 '14 19:11 vmlf01

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

just-boris avatar Nov 05 '14 20:11 just-boris

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 avatar Nov 05 '14 22:11 vmlf01

@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

just-boris avatar Nov 06 '14 09:11 just-boris

Landed in 7bbf6cb.

vmlf01 avatar Nov 09 '14 14:11 vmlf01

Thanks!

just-boris avatar Nov 09 '14 16:11 just-boris

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.

joaoborsoi avatar Dec 30 '15 09:12 joaoborsoi

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.

lock[bot] avatar Jan 26 '19 00:01 lock[bot]