Utilizing ExtJS: Defining default settings for panel items within nested objects

This particular question is part of a discussion regarding How to set defaults for Grid columns within initComponent. It has been shared here independently as per the advice given by @scebotari66 in the main post.

Below, you can see the use of Ext.Array.map to define default values for related functions.

// Statement
    initComponent: function () {
    var me = this;
    me.items = Ext.Array.merge(
        me.getFormSt(),
        Ext.Array.map(me.getForm(), function (listFldConfig) { //Utilizing array map function to set flex property for subset fields
            listFldConfig.flex = 1;
            return listFldConfig;
        }),
        me.getFormEnd()
    );
    me.callParent(arguments)
},

// Implementation
getForm: function () {
        var me = this;
        var form = [
            { // Array.map func. sets `flex` to this obj.
                xtype: 'fieldcontainer',
                layout: { type: 'vbox', align: 'stretch', pack: 'start' },
                items: [
                    {
                        xtype: 'fieldcontainer',
                        layout: 'hbox',
                        items: [
                            {
                                xtype: 'foofield',
                                //flex: 1 //However, I aim to set `flex` as default for this object in the nested items array
                            },
                            {
                                xtype: 'barfield',
                                //flex: 1 //Nevertheless, I intend to set `flex` as default for this object in the nested items array
                            }

The current implementation works as intended, but in this scenario, I am creating a fieldcontainer object that includes all other elements and items inside. The use of Array.map only applies the flex configuration to the first fieldcontainer object. My requirement is to specify the flex configuration solely for the nested items containing foofield and barfield.

Answer №1

The default settings for containers can be set using the defaults configuration:

xtype: 'fieldcontainer',
layout: 'hbox',
defaults: {
    flex: 1
},
items: [
    {
        xtype: 'foofield',
    },
    {
        xtype: 'barfield',
    }

For nested containers, you can nest multiple defaults configurations within each other:

defaults: {
    defaults: {
        flex: 1
    },
    flex: 1
}

It's important to be cautious when including an xtype configuration within the defaults object as it may lead to unexpected outcomes. Instead, utilize the defaultType configuration to specify the default type of child elements within a container.

Answer №2

After being inspired by @NarendraJadhav, I have developed my own framework...

Concept:

Ext.define('MyApp.BaseFldCon', {
    extend: 'Ext.form.FieldContainer',
    xtype: 'basefldcon'
});

Ext.define('MyApp.VBoxFldCon', {
    extend: 'MyApp.BaseFldCon',
    xtype: 'vboxfldcon',
    layout: {
        type: 'vbox',
        align: 'stretch',
        pack: 'start'
    }
});

Ext.define('MyApp.HBoxFldCon', {
    extend: 'MyApp.BaseFldCon',
    xtype: 'hboxfldcon',
    layout: {
        type: 'hbox'
    },
    defaults: {
        flex: 1
    }
});

Execution:

{
   xtype: 'vboxfldcon',
   items: [
            {
              xtype: 'hboxfldcon',
              items: [
                       {
                           xtype: 'foofield',
                        },
                        {
                           xtype: 'barfield'
                        },
                        {
                           xtype: 'foocombo'
                        }
                     ]
             },

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Error: There was an issue registering the component as the target container is not recognized as a valid DOM element

Upon executing the React code below, I encountered the following error: import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <div id="root"> <h1>Hello, world!</h1></div>, document ...

Open an external program

I'm currently working on a local web application and I want to be able to trigger an external application using a button click. I came across this code that works perfectly in an .html file with Internet Explorer, but when I try to implement it within ...

Create a jQuery URL within the $.ajax function

Attempting to execute a $.ajax call and send data to a php file. The php file is situated in a component's directory, while the js file is located in the webroot directory. How can the url section of the $.ajax be configured correctly to point to the ...

Tips for updating the browser address bar URL using angularJS without causing a page refresh

As a newcomer to angularJS, I have been tasked with a project. I encountered an issue where calling an angular function on ng-click did not change the URL in the browser address bar. However, when I used pure JavaScript and called the function, it success ...

Oops! Make sure to explicitly allow the dependency @types/html2canvas by adding it to the "allowedNonPeerDependencies" option

After installing the html2canvas package in my Angular library project, I encountered an error when compiling in production mode using the command ng build --prod. The specific error message is as follows: ERROR: Dependency @types/html2canvas must be exp ...

"Successfully making AJAX calls on localhost, but encountering issues when trying to make them online

Whenever a visitor navigates to a specific page (referred to as page1), the PHP script is initiated to load the HTML content for an array that contains data about the users. After the page has finished loading (DOM ready), I utilize jQuery to make an AJAX ...

Is there a solution for converting arrays with duplicate keys to XML?

It is known that having duplicate keys in an array is not possible. The scenario here involves sending data to an API in XML format. Before converting the data to XML and sending it to the API, it needs to be held in an Array. The API only accepts the spec ...

A variety of products combined into a single form

I am looking to enhance my form by allowing users to add multiple entries before submitting, similar to an "add to cart" feature. The added entries should be displayed on the same page in a separate div along with a submit button. Once the user is ready, t ...

What sets apart the usage of `import Anything from #anywhere` from not importing anything at all?

When utilizing the autoimport feature of Nuxt 3: Are there any implications (such as types, performance, bundle size, tree shaking, etc.) when using the # alias to import something as opposed to not importing at all? Or is its sole purpose to provide expl ...

Increase the vertical dimension of the R 3D array

Looking to expand an array of size c(1,n,m) by repeating the first row k times to create an array of size c(k,n,m). For instance: x <- array(1:6, c(1,3,2)) If k is 3, the expanded array would be: , , 1 [,1] [,2] [,3] [1,] 1 ...

The JsTree-grid is failing to show the information

I'm currently using the JsTree Ajax lazy load functionality along with JsTree-grid to showcase my data. However, I've encountered a problem when attempting to display the data in the second column using JsTree-grid. Here is a snippet of the JSON ...

Extend jQuery deeply, only replacing values and not adding new keys

For instance, consider the following two JSON objects: First Object: { "surname" : "Raghuvanshi", "work" : { "title": "title1" }, "name" : "Navin" } Second Object: { "work" : { "title": "title2", "field": "field2" }, "name" ...

The problem of width and display arises when utilizing highchart

I am attempting to create a select option that will display a different chart when changed. However, I am encountering two main issues: 1. The chart is not displaying properly within the div width. 2. How can I hide other charts when one is displayed? JS ...

The program encountered an issue with accessing the 'ref' property, as it was not defined

While creating a basic web app using Vue, Firebase, and Vuefire, I encountered an issue where I received an error message saying "Uncaught TypeError: Cannot read property 'ref' of undefined" when attempting to access my Firebase db variable withi ...

Adjusting the height of a GAS iframe in WordPress with iframe-resizer: A step-by-step guide

I would like to embed an iframe of my Google Application Script Web into my WordPress site without the scroll bar. Refer to the image below for context. https://i.stack.imgur.com/7L6Tw.png I encountered an error message while attempting to use the iframe ...

methods for calculating the overall quantity of sections in a string division

Imagine a scenario where a user enters a string into a text box in this format: part1,part2,part3,part4.........partn Is there a way to determine the total number of parts in that string? I attempted to solve this by using the following code: dim part( ...

Sorting through a table based on the name of the element

I am currently working on filtering an HTML table using a search form. It's working great, but I'm facing an issue where the filtered elements are trying to fill the entire width of the table instead of maintaining their original width (which is ...

Retrieve the server code periodically and automatically refresh the form elements

Let's kick things off by explaining how the application functions: (please note there are multiple users on the page such as Patient M, Patient E, and so forth) 1) Check In: Next to Patient X's name, you will find a button labeled Check In. This ...

Choosing image identifiers dynamically upon click

Greetings! I have a setup where images are pulled from a database and displayed in a div. When any image is clicked, a modal showing product details pops up. To make the modal work, I am using JavaScript to get the src of the clicked image and then displa ...

What is the best way to encapsulate a child's properties within a function?

Is there a way to automate wrapping each child of an object with a function? // current code import authController from "./authController"; import appController from "./appController"; import userController from "./userController&q ...