vitalets / angular-xeditable

Edit in place for AngularJS
http://vitalets.github.io/angular-xeditable
MIT License
1.91k stars 403 forks source link

Set value of amount inside of ng-repeat based off of isActive #606

Closed westerncj closed 7 years ago

westerncj commented 7 years ago

I have an ng-repeat editable form like below. How can I set the value of amount to 0 when it's disabled by the editable-checkbox (isActive)? I have to working so it disables the amount input when editableDataForm.$data.isActive, but I can't set the value to 0.

<tr ng-repeat="row in vm.data">
    <td>
        <span editable-checkbox="row.isActive"
              e-name="isActive" e-form="editableDataForm">
        </span>
    </td>
    <td>
        <span editable-text="row.amount"
              e-name="amount" e-form="editableDataForm" e-ng-disabled="editableDataForm.$data.isActive">{{row.amount}}</span>
    </td>
</tr>
ckosloski commented 7 years ago

Did you try using an e-ng-change on the checkbox to set the row.amount to 0 when it's checked?

westerncj commented 7 years ago

If I set row.amount using e-ng-change, then when the cancel button is clicked the value is set to zero.

I tried something like this:

e-ng-change="editableDataForm.$data.amount = (editableDataForm.$data.isActive) ? '0' : row.amount">

ckosloski commented 7 years ago

what about also changing row.amount?

westerncj commented 7 years ago

If I change row.amount, the underlying model is changed. I'd like to retain the original values if the Cancel button is clicked.

ckosloski commented 7 years ago

What happens with this code? e-ng-change="editableDataForm.$data.amount = (editableDataForm.$data.isActive) ? '0' : row.amount">

westerncj commented 7 years ago

When using that code, it doesn't change amount to 0 in edit mode.

ckosloski commented 7 years ago

This seems to work, the value is updated and reverted if cancelled...but the ui doesn't seem to reflect the change until after the save/cancel.

e-ng-change="update(editableDataForm)"

 $scope.update = function (form) {
      form.amount.value = 0;
      form.amount.$viewValue = 0
  }
westerncj commented 7 years ago

I get this error: TypeError: Cannot set property 'value' of undefined

If I console.log the form coming in I don't see the value or $viewValue properties.

ckosloski commented 7 years ago

Then I would need to seem more of your code.

ckosloski commented 7 years ago

@westerncj are you still having an issue?