在验证失败时,请关注需要a2lixTranslation的选项卡

时间:2018-06-14 07:38:50

标签: javascript jquery symfony symfony-forms a2lix-translation

我正在使用a2lix/translation-form-bundle: 2.1。我的表格:

add('translations',TranslationsType::class,      
[
                'fields' => [
                    'title' => [
                        'field_type' =>
                            TextType::class,
                    ],
                ],
                'required_locales' => ['en', 'lt'],
                'required'=>true,]
        );

当我填写表格并且表格失败时。如果有空字段title,我希望收到通知。此刻,我无法保存表格,但它并不是我的空场的焦点,这是空的。 经过一些调查,我需要在active上设置li      

        <li >
            <a href="#" data-toggle="tab" data-target=".form_translations_en_a2lix_translationsFields-en">
                En
                                    *                </a>
        </li>

        <li class="active">
            <a href="#" data-toggle="tab" data-target=".form_translations_da_a2lix_translationsFields-lt">
                Lt
                [Default]                    *                </a>
        </li>
            </ul>

&#13;
&#13;
// Manage focus on right bootstrap tab when invalid event (A2lixTranslation tab or not, and inner tabs include)
    $(':input', 'div.tab-content').on('invalid', function(e) {
        var $tabPanes = $(this).parents('div.tab-pane');

        $tabPanes.each(function() {
            var $tabPane = $(this);

            if (!$tabPane.hasClass('active')) {
                var $tabNavs = $tabPane.parent('.tab-content')
                                       .siblings('ul.nav.nav-tabs');

                // Tab target by id
                if (this.id) {
                    $tabNavs.find('a[href="#'+ this.id +'"], a[data-target="#'+ this.id +'"]')
                            .trigger('click');

                    return true;
                }

                // Tab target by class for a2lixTranslation
                var a2lixTranslClass = /a2lix_translationsFields-[\S]+/.exec(this.className);
                if (a2lixTranslClass.length) {
                    $tabNavs.find('a[data-target=".'+ a2lixTranslClass[0] +'"]')
                            .trigger('click');

                    return true;
                }
            }
        });

        return true;
    });
&#13;
&#13;
&#13;

0 个答案:

没有答案