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

I have a textfield in a Panel. For example:{xtype:'textfield',id:'usap8',width:199,

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744391837a4571942.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信