最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - What is the use of allowBlank: false in extjs fields - Stack Overflow

programmeradmin5浏览0评论

I have a textfield in a Panel. For example:

{
    xtype:'textfield',
    id:'usap8',
    width:199,
    height:26,
    colspan:1,
    margin: '1 0 1 0',
    allowBlank: false,
    fieldStyle: 'text-align: center;'
}

Will I be able to restrict the panel submission? If not, what is the use of allowBlank config?

I have a textfield in a Panel. For example:

{
    xtype:'textfield',
    id:'usap8',
    width:199,
    height:26,
    colspan:1,
    margin: '1 0 1 0',
    allowBlank: false,
    fieldStyle: 'text-align: center;'
}

Will I be able to restrict the panel submission? If not, what is the use of allowBlank config?

Share Improve this question edited Oct 29, 2014 at 13:56 Alexander 20.3k21 gold badges83 silver badges170 bronze badges asked Oct 29, 2014 at 7:22 FreakyuserFreakyuser 2,81417 gold badges48 silver badges74 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

allowBlank does not automatically restrict form submission.

Instead, it is a config that is for instance relevant if you ask whether the form is valid:

if(form.isValid()) form.submit()

In the isValid function, all fields are asked whether they are valid:

invalid = me.getFields().filterBy(function(field) {
        return !field.validate();
    });

field.validate() calls field.isValid(), which calls field.getErrors().

The Ext.form.field.Text has the following line in its function getErrors:

if (trimmed.length < 1 || (value === me.emptyText && me.valueContainsPlaceholder)) {
    if (!me.allowBlank) {
        errors.push(me.blankText);
    }

and HERE the config you have said has the effect that an error is thrown if the field is blank.

That error then ripples back through aforementioned functions until form.isValid() returns false (but you could also find out about the error if you call field.validate(), field.isValid() or field.getErrors() manually)...

For restricting form panel text value submission, use

submitvalue: false

Refer: http://docs.sencha./extjs/5.0/apidocs/#!/api/Ext.form.field.File-cfg-submitValue

While, allowBlank:false will restrict the form submission if the field is blank.

allowBlank simply tells the Validator that your field may or may not be empty upon validation/submission. If you do validation of panel/form then allowBlank:false should make sure you can't proceed with a blank/empty field there.

发布评论

评论列表(0)

  1. 暂无评论