<vn-crud-model
    vn-id="model"
    url="ClientContacts"
    fields="['id', 'name', 'phone', 'clientFk']"
    link="{clientFk: $ctrl.$params.id}"
    data="contacts"
    auto-load="true">
</vn-crud-model>
<vn-watcher
    vn-id="watcher"
    data="contacts"
    form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" class="vn-w-md">
    <vn-card class="vn-pa-lg">
        <vn-horizontal ng-repeat="contact in contacts">
            <vn-textfield
                vn-one
                label="Name"
                ng-model="contact.name"
                rule="ClientContact">
            </vn-textfield>
            <vn-textfield
                vn-one
                label="Phone"
                ng-model="contact.phone"
                rule="ClientContact"
                vn-focus>
            </vn-textfield>
            <vn-none>
                <vn-icon-button
                    vn-tooltip="Remove contact"
                    icon="delete"
                    tabindex="-1"
                    ng-click="model.remove($index)">
                </vn-icon-button>
            </vn-none>
        </vn-horizontal>
        <vn-one>
            <vn-icon-button
                vn-bind="+"
                vn-tooltip="Add contact"
                icon="add_circle"
                ng-click="$ctrl.add()">
            </vn-icon-button>
        </vn-one>
    </vn-card>
    <vn-button-bar>
        <vn-submit
            disabled="!watcher.dataChanged()"
            label="Save">
        </vn-submit>
        <!-- # #2680 Undo changes button bugs -->
        <!-- <vn-button
            class="cancel"
            label="Undo changes"
            disabled="!watcher.dataChanged()"
            ng-click="watcher.loadOriginalData()">
        </vn-button> -->
    </vn-button-bar>
</form>