# all files / Core/Validators/ ExampleNameValidator.js

92.31% Statements 12/13
100% Branches 0/0
75% Functions 3/4
92.31% Lines 12/13

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37

    1
    1

    1

    1
    1

    1

    7

    1
    8
    5
    5

    1
     'use strict';

    // Utilities:
    var _ = require('lodash');
    var Promise = require('bluebird');

    // Module:
    var Core = require('../Core');

    // Dependencies:
    require('../Services/ValidationService');
    require('../../features/FeatureEditor/Models/StepDeclarationModel');

    var ExampleNameValidator = function (
        validationService,
        StepDeclarationModel
    ) {
        return {
            restrict: 'A',

            require: 'ngModel',

            link: link
        };

        function link ($scope, $element, $attrs, ngModelController) {
            ngModelController.$validators.exampleName = function (value) {
                var variableNames = StepDeclarationModel.getExampleVariableNames(value);
                return _.filter(variableNames, function (variableName) {
                    return validationService.validateVariableName(variableName);
                }).length === variableNames.length;
            };
        }
    };

    Core.directive('exampleName', ExampleNameValidator);