简体   繁体   English

如何在类星体对话框中设置默认按钮取消

[英]How set default button on cancel in quasar dialog

I Need to put focus on cancel button of my confim dialog box.我需要把重点放在我的确认对话框的取消按钮上。

I work with vue/Quasar.我与 vue/Quasar 合作。 I've a delete button, and before deletion I create a confim dialogbox.我有一个删除按钮,在删除之前我创建了一个确认对话框。 It's Ok.没关系。 But just want the default button focused is "Cancel" not "ok"但只希望默认按钮的焦点是“取消”而不是“确定”

this.$q.dialog({
    title: 'Confirmation',
    message: "Etes-vous sûr de vouloir supprimer l''entité: " ,
    ok: 'Suppression',
    cancel: {
        push: true,
        color: 'negative',
        label:"Annuler"
    },
    persistent: true
})

With that it'sok button selectd by default not the cancel button有了它,默认选择的是按钮而不是取消按钮

UPDATE更新

this.$q.dialog({
    title: 'Confirmation',
    message: "Etes-vous sûr de vouloir supprimer l''entité: " + libelle,
    ok: {
        push: true,
        label: "Suppression",
        tabindex: 1
    },
    cancel: {
        push: true,
        color: 'negative',
        label: "Annuler",
        tabindex: 0
    },
    persistent: true
})

Change the tabindex but not the autofocus on button更改 tabindex 但不更改按钮上的自动对焦

UPDATE 2更新 2

this.$q.dialog({
    ref: "ConfirmDialog",
    title: 'Confirmation',
    message: "Etes-vous sûr de vouloir supprimer l''entité: " + libelle,
    ok: {
        push: true,
        label: "Suppression",
        tabindex: 1
    },
    cancel: {
        ref:"btnAnnul",
        push: true,
        color: 'negative',
        label: "Annuler",
        tabindex: 0
    },
    persistent: true,
    created: setTimeout(x => {this.$nextTick(() => this.focus());}, 1000)
})

I Progress, Now I can execute after create dialog event, but don't know how access to the button.我进步了,现在我可以在创建对话框事件后执行,但不知道如何访问按钮。 I see too Autofocus="autofocus" on ok button我在确定按钮上也看到 Autofocus="autofocus"

Perhpas better if I put my full compoment.如果我全力以赴,可能会更好。 It's a tree with option on end of each line.这是一棵树,每行末尾都有选项。 One option is delete.一种选择是删除。 I Create a dialog to ask confirmation.我创建一个对话框要求确认。

Vue.component('select-tree-nocheck', {
    inject: ['IsConnected', 'showNotifError'],
    props: ['treedata'],
    template: ' <div class="q-pa-md  q-col-gutter-sm">\
                    <q-input ref="filter" filled v-model="treedata.filter" label="Filtrer">\
                        <template v-slot: append>\
                            <q-icon v-if="treedata.filter !== \'\'" name="clear" class="cursor-pointer" v-on:click="resetFilter" />\
                        </template>\
                    </q-input>\
                    <q-tree ref="tree" class="col-12" accordion v-bind:nodes="treedata.nodes" node-key="id"  v-bind:filter="treedata.filter">\
                        <template v-slot:default-header="prop">\
                            <div class="row">\
                                  <div>{{ prop.node.label }}\
                            &nbsp;&nbsp;...<q-menu anchor="top right" self="top left"><q-list style="min-width: 100px">\
                                   
                                    <q-item clickable v-close-popup><q-item-section v-on:click="Suppression(prop.node.id,prop.node.label)">Supprimer</q-item-section></q-item>\
                                </q-list></q-menu>\
                            </div></div>\
                        </template>\
                    </q-tree>\
                </div>',
    methods: { 
        Suppression(value, libelle) {
            this.IsConnected().then(retour => {
                if (retour == 1) {
                    this.$q.dialog({
                        $ref: "ConfirmDialog",
                        title: 'Confirmation',
                        message: "Etes-vous sûr de vouloir supprimer l''entité: " + libelle,
                        ok: {
                            push: true,
                            label: "Suppression",
                            tabindex: 1
                        },
                        cancel: {
                            $ref:"btnAnnul",
                            push: true,
                            color: 'negative',
                            label: "Annuler",
                            tabindex: 0
                        },
                        persistent: true,
                        created: setTimeout(x => {this.$nextTick(() => this.focus());}, 1000)
                    }).onOk(() => {
                        
                    });
                }
            });
        },
        resetFilter() {
            this.treedata.filter = '';
            this.$refs.filter.focus();
        }
    },
});

Have you checked this out @show event ?你检查过这个@show 事件吗?

  focus: function () {
    this.$refs.htmlElementToFocus.focus()
  }

Finally... Instead of search from "this", I use simple javascript function最后......而不是从“this”搜索,我使用简单的 javascript function

created: setTimeout(x => { this.$nextTick(() => document.getElementsByClassName('bg-negative')[0].focus()); }, 1000)

It's not beautifull but it works cause I've just one element with specific class bg-negative它并不漂亮,但它有效,因为我只有一个具有特定 class bg-negative 的元素

use focus:'cancel' my examples https://codepen.io/greyufo/pen/GRZvOoP使用焦点:'取消'我的例子https://codepen.io/greyufo/pen/GRZvOoP

this.$q.dialog({
                ...
                focus:'cancel',
                ...
                })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM