Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. netupApp.directive('between', function(Validators) {
  2. return {
  3. restrict: 'A',
  4. require: 'ngModel',
  5. scope: {
  6. min: '@min',
  7. max: '@max',
  8. inclusive: '@inclusive'
  9. },
  10. link: function(scope, element, attrs, ctrl) {
  11.  
  12. var properties = {
  13. min: scope.min,
  14. max: scope.max,
  15. inclusive: scope.inclusive
  16. };
  17.  
  18. ctrl.$validators.between = function(modelValue, viewValue) {
  19. return Validators.between(properties).isValid(modelValue);
  20. };
  21. }
  22. };
  23. });
  24.  
  25. netupApp.factory('Validators', function () {
  26. return {
  27. between: function(properties) {
  28. var validator = {
  29. inclusive: !!properties.inclusive,
  30. min: Number(properties.min),
  31. max: Number(properties.max),
  32. isValid: function(value) {
  33. if (isNaN(parseFloat(value)) || !isFinite(value)) {
  34. return false;
  35. }
  36. if (this.inclusive) {
  37. return (value >= this.min && value <= this.max);
  38. } else {
  39. return (value > this.min && value < this.max);
  40. }
  41. }
  42. };
  43. return validator;
  44. }
  45. }
  46. });
  47.  
  48. <input name="video_bitrate_max" between
  49. min="{{parameters.video_bitrate_max.validators.between.parameters.min}}"
  50. max="{{parameters.video_bitrate_max.validators.between.parameters.max}}"
  51. inclusive="{{parameters.video_bitrate_max.validators.between.parameters.inclusive}}"
  52. type="number" class="form-control input-xs"
  53. ng-model="preset.parameters.common.video_bitrate_max"
  54. ng-disabled="preset.parameters.common.rate_control === 'CBR'">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement