简体   繁体   English

使用ext.js 4渲染“正常”复选框

[英]Rendering a “normal” checkbox with ext.js 4

I'm trying to do something, i think, that should be relatively simple with EXT.js 4, but I can not find an answer. 我认为我正在尝试使用EXT.js 4进行相对简单的操作,但是我找不到答案。 I'm trying to create a checkbox with a type of "checkbox" currently when I try it renders it as a type="button" 我尝试将其呈现为type =“ button”时,目前正在尝试创建一种类型为“ checkbox”的复选框

here is a sample of what I'm doing (I belive this code comes from Sencha itself, but it is what I am trying to do) 这是我正在做的示例(我相信这段代码来自Sencha本身,但这是我正在尝试做的事情)

THIS CODE 本守则

Ext.create('Ext.form.Panel', {
    bodyPadding: 10,
    width      : 300,
    title      : 'Pizza Order',
    items: [{
        xtype      : 'fieldcontainer',
        fieldLabel : 'Toppings',
        defaultType: 'checkboxfield',
        items: [{
            boxLabel  : 'Anchovies',
            name      : 'topping',
            inputValue: '1',
            id        : 'checkbox1'
        }, {
            boxLabel  : 'Artichoke Hearts',
            name      : 'topping',
            inputValue: '2',
            checked   : true,
            id        : 'checkbox2'
        }, {
            boxLabel  : 'Bacon',
            name      : 'topping',
            inputValue: '3'
            id        : 'checkbox3'
        }]
    }],
    bbar: [{
        text: 'Select Bacon',
        handler: function() {
            var checkbox = Ext.getCmp('checkbox3');
            checkbox.setValue(true);
        }
    },
    '-',
    {
        text: 'Select All',
        handler: function() {
            var checkbox1 = Ext.getCmp('checkbox1'),
                checkbox2 = Ext.getCmp('checkbox2'),
                checkbox3 = Ext.getCmp('checkbox3');

            checkbox1.setValue(true);
            checkbox2.setValue(true);
            checkbox3.setValue(true);
        }
    },{
        text: 'Deselect All',
        handler: function() {
            var checkbox1 = Ext.getCmp('checkbox1'),
                checkbox2 = Ext.getCmp('checkbox2'),
                checkbox3 = Ext.getCmp('checkbox3');

            checkbox1.setValue(false);
            checkbox2.setValue(false);
            checkbox3.setValue(false);
        }
    }],
    renderTo: Ext.getBody()
});

RENDERS 渲染器

<input type="button" hidefocus="true" autocomplete="off" class="x-form-field x-form-checkbox x-form-cb" id="checkbox1-inputEl" aria-invalid="false" data-errorqtip="">

Notice the type="button"? 注意到type =“ button”吗? I nee the type to be a "checkbox" 我将类型设为“复选框”

Let me include the reason, maybe I am approaching this wrong. 让我列出原因,也许我正在解决这个错误。 I am trying to make JAWS reader read the checkbox the way it should. 我试图让JAWS阅读器以应有的方式阅读复选框。 As a type "button" JAWS reader reads it like a button and dose not read the label that goes with the check box. 作为类型的“按钮”,JAWS阅读器像按钮一样读取它,而不会读取复选框附带的标签

Hope this makes since, please ask any question you need to and thanks for any help. 希望此后,请提出您需要的任何问题,并感谢您的帮助。

Ross 罗斯

You can do this using config autoEl . 您可以使用config autoEl执行此操作。 Check this fiddle: http://jsfiddle.net/vdazU/3262/ 检查此小提琴: http : //jsfiddle.net/vdazU/3262/

{
    xtype: 'component',
    autoEl: {
        html: '<input type="checkbox" id="checkbox1" name="topping" >Anchovies'
}

If you inspect the DOM, you will be able to see a html input checkbox. 如果您检查DOM,将可以看到html输入复选框。

I had the same problem, so almost 2 years later, here's your answer: 我遇到了同样的问题,所以差不多2年后,这是您的答案:

You need to include the css! 您需要包括CSS! It took me hours to figure this out. 我花了几个小时才弄清楚这一点。

<link rel="stylesheet" href="http://cdn.sencha.com/ext/gpl/4.2.1/packages/ext-theme-gray/build/resources/ext-theme-gray-all.css">

BTW, put a comma after the 3. 顺便说一句,在3.之后加上逗号。

inputValue: '3',

I had run your code at my end and its working fine. 我在最后运行了您的代码,并且运行正常。 I am using extjs 6.0.2 and I think what you are seeing is that box that needs to be checked prefix to the label. 我正在使用extjs 6.0.2,我认为您看到的是需要检查标签前缀的框。 It always remains as a button only. 它始终仅保留为一个按钮。 Even if you use a radiofield, then also it will be type="button" in dom because that box has to handle click event which can be handled by type="button". 即使您使用无线电场,它在dom中也将是type =“ button”,因为该框必须处理可以由type =“ button”处理的click事件。 Can you provide the reason why you need it as type="checkbox"? 您能否以type =“ checkbox”的形式提供需要它的原因?

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

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