vitalets / angular-xeditable

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

editable-select and $watchCollection bug #699

Open johnzakariasabry opened 7 years ago

johnzakariasabry commented 7 years ago

hi dears i made editable-select to call a directive function but it does not work for me

i am using credit card validation in https://gist.github.com/lrvick/8789669 but i want to make it by editable-select but the function is not called at all..

when i made it with normal function it gives alerts when i tried to alert anything but in using watch collection is does not work

<span editable-select="ccinfo.month" e-ng-options="month.text for month in months track by month.value" e-required e-card-expiration e-name="cardExpiryMonth" ng-model="ccinfo.month"> {{ ccinfo.month.value || 'empty' }} </span> <span editable-select="ccinfo.year" e-ng-options="year as year for year in [] | range:currentYear:currentYear+13" e-card-expiration e-required e-name="cardExpiryYear" ng-model="ccinfo.year"> {{ ccinfo.year || 'empty' }} </span> and the directive function is `'use strict';

angular.module('signupApp') .directive('cardExpiration', function () { return { require: 'ngModel', link: function postLink(scope, element, attrs, ctrl) { scope.$watchCollection('[ccinfo.month, ccinfo.year]', function (newValues, oldValues) { ctrl.$setValidity('past', false);

      if (typeof newValues["0"] !== 'undefined' && typeof newValues["1"] !== 'undefined') {
        ctrl.$setValidity('past', true);
        if (newValues["1"] == scope.currentYear && newValues["0"].value < scope.currentMonth) {
          ctrl.$setValidity('past', false);
        }
      }
    });
  }
};

})`

ckosloski commented 7 years ago

So you select an item in editable-select and upon save you are expecting the cardExpiration directive watch to have done something?

johnzakariasabry commented 7 years ago

the problem is ctrl value

i have 2 pull donwn menu one for year and other for month.. when i change value of month it only set validity for months and when i change the year it set validity for only year

so how to set validity for ctrl that is not clicked notice that i know its name , id and model id

ckosloski commented 7 years ago

Why can't you call an function in eitheronBeforeSave or onAfterSave that will display an error message based upon the value that update and the other input?

johnzakariasabry commented 7 years ago

i dont know how to call directive in on before save or i will make it into controller?

i want to make it on change

ckosloski commented 7 years ago

Documentation for onbeforesave andonaftersave are here.

If you want to do something on change, just add e-ng-change and have it call a function.