<commit_before>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact <EMAIL>. 
 */
(function() {

    'use strict';

    /**
     * @ngdoc directive
     * @restrict E
     * @name openlmis-form.directive:inputErrorSpan
     *
     * @description
     * Adds support for displaying validation errors to the input element. This directive will
     * attach a span displaying a error based on the ngModelController errors.
     *
     * @example
     * To use this directive simply include the openlmis-form module. It will automatically extend
     * all the input elements that reside inside of the form.
     * ```
     * <form>
     *     <input ng-model="soomeModel" />
     * </form>
     * ```
     */
    angular
        .module('openlmis-form')
        .directive('input', inputErrorSpan);

    inputErrorSpan.$inject = ['messageService', 'errorSpanFactory'];

    function inputErrorSpan(messageService, errorSpanFactory) {
        var directive = {
            link: link,
            require: [
                '^?form',
                '?ngModel'
            ],
            restrict: 'E'
        };
        return directive;

        function link(scope, element, attrs, controllers) {
            var formCtrl = controllers[0],
                ngModelCtrl = controllers[1],
                span;

            if (!formCtrl || !ngModelCtrl) return;

            if (attrs.type === 'checkbox' || attrs.type === 'radio') {
                span = element.parents('fieldset').find('span.error');

                if(!span.length) {
                    span = angular.element('<span class="error"></span>');
                }

                if (attrs.type === 'checkbox') {
                    element.parents('fieldset').find('legend').after(span);
                } else {
                    element.parents('fieldset').append(span);
                }
            }

            errorSpanFactory.link(scope, element, attrs, controllers, span);
        }
    }



})();<commit_msg>OLMIS-1693: Put radio button error message at top of fieldset<commit_after>/*
 * This program is part of the OpenLMIS logistics management information system platform software.
 * Copyright © 2017 VillageReach
 *
 * This program is free software: you can redistribute it and/or modify it under the terms
 * of the GNU Affero General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *  
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU Affero General Public License for more details. You should have received a copy of
 * the GNU Affero General Public License along with this program. If not, see
 * http://www.gnu.org/licenses.  For additional information contact <EMAIL>. 
 */
(function() {

    'use strict';

    /**
     * @ngdoc directive
     * @restrict E
     * @name openlmis-form.directive:inputErrorSpan
     *
     * @description
     * Adds support for displaying validation errors to the input element. This directive will
     * attach a span displaying a error based on the ngModelController errors.
     *
     * @example
     * To use this directive simply include the openlmis-form module. It will automatically extend
     * all the input elements that reside inside of the form.
     * ```
     * <form>
     *     <input ng-model="soomeModel" />
     * </form>
     * ```
     */
    angular
        .module('openlmis-form')
        .directive('input', inputErrorSpan);

    inputErrorSpan.$inject = ['messageService', 'errorSpanFactory'];

    function inputErrorSpan(messageService, errorSpanFactory) {
        var directive = {
            link: link,
            require: [
                '^?form',
                '?ngModel'
            ],
            restrict: 'E'
        };
        return directive;

        function link(scope, element, attrs, controllers) {
            var formCtrl = controllers[0],
                ngModelCtrl = controllers[1],
                span;

            if (!formCtrl || !ngModelCtrl) return;

            if (attrs.type === 'checkbox' || attrs.type === 'radio') {
                span = element.parents('fieldset').find('span.error');

                if(!span.length) {
                    span = angular.element('<span class="error"></span>');
                }

                element.parents('fieldset').find('legend').after(span);
            }

            errorSpanFactory.link(scope, element, attrs, controllers, span);
        }
    }



})();
{'fraction_non_alphanumeric': 0.09863569321533923, 'fraction_numerical': 0.00331858407079646, 'mean_word_length': 2.213862559241706, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4661999', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1331, 'n_words': 494}