herme 0
herme 0

Reputation: 972

extjs bind parent's bindable property to child's

I have a container with one or more form fields in it. I would like to bind the hidden property of the parent container to the disabled property of the child items How do we do this?

I have a fiddle here to illustrate. I have fields in my optional container that are required. So when visible, they should be required, when hidden they should be optional. I know that I can add a handler that can set allowBlank: true but that seems tedious.

Upvotes: 0

Views: 212

Answers (2)

LightNight
LightNight

Reputation: 851

Register parent's hidden state in viewModel to get parents state in child component.

change "containerHidden" property in viewModel to true or false to test it. here is fiddle

viewModel:{
    data:{
        containerHidden:true
    }
},
defaults: {
    labelAlign: "right"
},
items: [
    {
        xtype: "textfield",
        fieldLabel: "Name",
        allowBlank: false
    },
    {
        xtype: "datefield",
        fieldLabel: "Date of Birth",
        emptyText: "18+ gets more options",
        allowBlank: false,
        listeners: {
            change: "onDoBChange"
        }
    },
    {
        xtype: "container",
        reference: "AgeRestrictedArea",
        bind:{
            hidden:"{containerHidden}"
        },
        defaults: {
            labelAlign: "right"
        },
        items: [
            {
                xtype: "textfield",
                fieldLabel: "Hobby",
                allowBlank:false,
                bind:{
                    disabled: "{containerHidden}"
                }

            }
        ]
    }
]

Upvotes: 1

pvlt
pvlt

Reputation: 1863

You can do it with help hide\show listeners fiddle

Upvotes: 0

Related Questions