vitalets / angular-xeditable

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

ColumnEdit validation not working #513

Closed atodicebear closed 8 years ago

atodicebear commented 8 years ago

Hey, I took the saveColumn and CheckName Functions and Copied them without changes, only adaptation to mine Variables.

**Controller**
    checkName(data) {
      console.log('checkName');
        if (data !== 'im the King') {
          return "Write King!!";
        }
      }
      // Edit Table Row
    saveColumn(column) {
      var results = [];
      angular.forEach(this.langV, (value) => {
        results.push(this.$http.patch('/api/dict_values/' + value.v_id, {
          id: value.v_id,
          value: value.value2,
          user_id: this.currentUser()._id,
          key_id: value._id,
          lang_id: this.$scope.select2
        }));
      });
      return this.$q.all(results);
    }
**HTML**
form editable-form name="valueForm" onaftersave="$ctrl.saveColumn('valueTranlate')" ng-show="valueForm.$visible">
                <button type="submit" ng-disabled="valueForm.$waiting" class="btn btn-primary">
                  Speichern
                </button>
<span editable-textarea="v.value2" e-name="valueTranslate" e-form="valueForm" e-rows="'7'" e-cols="'40'" onbeforesave="checkName($data)">
                {{v.value2 || 'empty' }}
              </span>

But it is not Invoking the checkName function. No Validation and not even the Console.log output. But the saveColumn is wokring fine?.

ckosloski commented 8 years ago

I don't think you are calling or defining your checkName function correctly. I can't tell if your function is available in $scope or not. The example has $scope.checkName = function(data) {. Also, your onaftersave function is using $ctrl.saveColumn('valueTranlate'). Maybe your need to do something similar $ctrl.checkName ($data)?

atodicebear commented 8 years ago

Got it running now thx :) Btw for what is the "column" in the saveColumn function?

  // Edit Table Row
$scope.saveColumn=function() { 
  var results = [];
  angular.forEach($scope.langV, (value) => {
    results.push($http.patch('/api/dict_values/' + value.v_id, {
      id: value.v_id,
      value: value.value2,
      user_id: Auth.getCurrentUser()._id,
      key_id: value._id,
      lang_id: $scope.select2
    }));
  });
  return $q.all(results);
};

I have removed the column in $scope.saveColumn = function(column) { And it is still saving everything normal without Errors.

ckosloski commented 8 years ago

In the example, the "column" parameter was used to load data from the array. results.push($http.post('/saveColumn', {column: column, value: user[column], id: user.id}));

You are doing something different in your saveColumn function so it's not needed.

atodicebear commented 8 years ago
  // Edit Table Row
$scope.saveColumn=function() {
  var results = [];
  angular.forEach($scope.langV, (value) => {
    results.push($http.patch('/api/dict_values/' + value.v_id, {
      id: value.v_id,
      value: value.value2,
      user_id: Auth.getCurrentUser()._id,
      key_id: value._id,
      lang_id: $scope.select2
    }));
  });
  return $q.all(results);
};

That is what I did and it is getting the Data from all Fields right with the Depending other Datas. Can be closed because it is working. Or Discuss for other/me/you why it is working.

ckosloski commented 8 years ago

I think you can go ahead and close this issue.