<commit_before>import '@fp_js_form_validator';
import '@vanio_web/js/validators/UserPassword';

function findTabsByPanes($panes: JQuery): JQuery
{
    let $tabs = $();

    $panes.each((index: number, pane: HTMLAnchorElement) => {
        const $pane = $(pane);

        $pane.closest('.tabbable').find('> .nav-tabs > li > a').each((index: number, link: HTMLAnchorElement) => {
            const $link = $(link);

            if ($pane.is($link.data('target') || $link.attr('href'))) {
                $tabs = $tabs.add($link.parent());

                return false;
            }
        });
    });

    return $tabs;
}

FpJsFormElement.prototype.onValidate = function (errors: any[]): void
{
    let $invalidFieldToFocus = $();
    let $invalidTabs = $();

    for (const id of Object.keys(errors)) {
        const $element = $(document.getElementById(id)!);
        const $field = $element.is(':input') ? $element : $element.find(':input')

        if (!$invalidFieldToFocus.length || $field.is(':focus')) {
            $invalidFieldToFocus = $field;
        }

        $invalidTabs = $invalidTabs.add(findTabsByPanes($element.closest('.tab-pane')));
    }

    const $tabsToFocus = findTabsByPanes($invalidFieldToFocus.parents('.tab-pane'));

    $invalidTabs.closest('.tabbable').find('> .nav-tabs > li, > .tab-content > .tab-pane')
        .removeClass(FpJsFormValidator.hasErrorClass)
        .removeClass('active');

    $invalidTabs.each((index: number, invalidTab: HTMLElement) => {
        const $invalidTab = $(invalidTab);
        const $link = $(invalidTab).find('> a');

        if (
            $invalidTab.is($tabsToFocus) || (
                !$invalidTab.prevAll().filter($invalidTabs).length
                && !$invalidTab.siblings().filter($tabsToFocus).length
            )
        ) {
            $invalidTab.addClass('active');
            $($link.data('target') || $link.attr('href')).addClass('active');
        }
    });

    $invalidTabs.addClass(FpJsFormValidator.hasErrorClass);
    $invalidFieldToFocus.focus();
};<commit_msg>Simplified tab switching in JS validator<commit_after>import '@fp_js_form_validator';
import '@vanio_web/js/validators/UserPassword';

function findTabsByPanes($panes: JQuery): JQuery
{
    let $tabs = $();

    $panes.each((index: number, pane: HTMLAnchorElement) => {
        const $pane = $(pane);

        $pane.closest('.tabbable').find('> .nav-tabs > li > a').each((index: number, link: HTMLAnchorElement) => {
            const $link = $(link);

            if ($pane.is($link.data('target') || $link.attr('href'))) {
                $tabs = $tabs.add($link.parent());

                return false;
            }
        });
    });

    return $tabs;
}

FpJsFormElement.prototype.onValidate = function (errors: any[]): void
{
    let $invalidFieldToFocus = $();
    let $invalidTabs = $();

    for (const id of Object.keys(errors)) {
        const $element = $(document.getElementById(id)!);
        const $field = $element.is(':input') ? $element : $element.find(':input')

        if (!$invalidFieldToFocus.length || $field.is(':focus')) {
            $invalidFieldToFocus = $field;
        }

        $invalidTabs = $invalidTabs.add(findTabsByPanes($element.closest('.tab-pane')));
    }

    const $tabsToFocus = findTabsByPanes($invalidFieldToFocus.parents('.tab-pane'));
    $invalidTabs.closest('.tabbable').find('> .nav-tabs > li').removeClass(FpJsFormValidator.hasErrorClass);

    $invalidTabs.each((index: number, invalidTab: HTMLElement) => {
        const $invalidTab = $(invalidTab);
        const $link = $(invalidTab).find('> a');

        if (
            $invalidTab.is($tabsToFocus) || (
                !$invalidTab.prevAll().filter($invalidTabs).length
                && !$invalidTab.siblings().filter($tabsToFocus).length
            )
        ) {
            $link.click();
        }
    });

    $invalidTabs.addClass(FpJsFormValidator.hasErrorClass);
    $invalidFieldToFocus.focus();
};
{'fraction_non_alphanumeric': 0.17650012553351746, 'fraction_numerical': 0.0, 'mean_word_length': 2.7094972067039107, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6178864', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1237, 'n_words': 189}