Class

Container

kiss.ui.Container(config, multiviewopt)

The Container derives from Component.

A Container is useful to embed other items. Containers can also embed other containers to build complex layouts.

The Container class should not be instanciated directly: it's the base class for the 2 types of containers:

  • Block, which is a simple "div" container
  • Panel, which has a header and is useful to build windows or modals, for example.

It's also possible to bind a Record to a container:

  • in this case, the record will be bound to all the container's fields (text, number, date, checkbox, select...)
  • the fields will be automatically synchronized with the Record, but only if their id matches a record's property
  • it's a 2-way binding:
    • if a field of the container is updated, the database will be updated automatically
    • if the database is updated, the fields will react to the change as well
Constructor

# new Container(config, multiviewopt)

Parameters:
Name Type Attributes Description
config object
multiview boolean <optional>

If true, only displays one item at a time

config.items Array.<object>

The array of contained items

config.record Record <optional>

Record to bind to the contained fields

View Source client/ui/abstract/container.js, line 55

this

Example
let myRecord = myModel.create({firstName: "Bob", lastName: "Wilson"})
await myRecord.save()

let myForm = createPanel({
 title: "Binding example",
 width: 300,
 height: 300,
 align: "center",
 verticalAlign: "center",

 record: myRecord, // Bind the record to the container's fields

 items: [
     {
         id: "firstName", // Updating the field will update the database
         type: "text",
         value: myRecord.firstName
     },
     {
         id: "lastName",
         type: "text",
         value: myRecord.lastName
     }
 ]
}).render()

await myRecord.update({firstName: "Will"}) // Updating the database will update the field in the UI

Methods

# addItem(item)

Add a child item into the container

Parameters:
Name Type Description
item object

Item JSON configuration

View Source client/ui/abstract/container.js, line 335

this

# collapseAll()

Find all the panels inside a container and collapse them recursively

View Source client/ui/abstract/container.js, line 387

this

# deleteItem(itemId)

Delete an item from the container

Parameters:
Name Type Description
itemId string

View Source client/ui/abstract/container.js, line 360

this

# expandAll()

Find all the panels inside a container and expand them recursively

View Source client/ui/abstract/container.js, line 372

this

# getComponentIds() → {Array.<string>}

Get the ids of all the contained items. Can be useful to check if a component is contained by this container.

View Source client/ui/abstract/container.js, line 175

Array.<string>

# getContainer() → {HTMLElement}

Returns the HTMLElement which is the real container of the component. It can differ depending on the component type. For example, for a panel, the container is the panel body.

View Source client/ui/abstract/container.js, line 165

The real component's container

HTMLElement

# getData(config) → {object}

Get fields data found in this container.

This method:

  • finds all the contained items which are fields
  • also explores nested containers, if any
Parameters:
Name Type Description
config object
useLabels boolean

If true, return data using field labels instead of field ids

View Source client/ui/abstract/container.js, line 455

object
Example
let formData = myForm.getData()
console.log(formData) // {title: "Training ICT", amount: 1234.56, dueDate: "2020-02-20T20:19:15Z"}

formData = myForm.getData({
 useLabels: true
})
console.log(formData) // {"Lead name": "Training ICT", "Lead amount": 1234.56, "Due date": "2020-02-20T20:19:15Z"}

# getFields() → {Array.<Object>}

Get all the fields found in this container

View Source client/ui/abstract/container.js, line 402

An array of objects containing the fields

Array.<Object>

# insertItem(item, position)

Insert a child item into the container at a specified position

Parameters:
Name Type Description
item object

Item JSON configuration

position number

View Source client/ui/abstract/container.js, line 348

this

# setColumns(numberOfColumns)

Dispatch container's content on multiple columns

Parameters:
Name Type Default Description
numberOfColumns number 1

View Source client/ui/abstract/container.js, line 648

this

# setData(data, rawUpdateopt)

Set the value of the fields found in this container, given a data object.

This method:

  • finds all the contained items which are fields
  • also explores nested containers, if any
  • set their value if the field id matches a property of the given data object
Parameters:
Name Type Attributes Description
data object
rawUpdate boolean <optional>

If true, the field's value is updated without triggering the "change" event. Default is false.

View Source client/ui/abstract/container.js, line 486

this

Example
const data = {title: "Training ICT", amount: 1234.56, dueDate: "2020-02-20T20:19:15Z"}
myForm.setData(data)

# setDisplayMode(mode)

Set the display mode

Parameters:
Name Type Default Description
mode string flex

"flex" | "inline-flex" | "block" | "inline-block"

View Source client/ui/abstract/container.js, line 668

# setItems(newItems)

Set container items.

Overwrite existing items if the container is not empty.

Parameters:
Name Type Description
newItems Array.<object>

Array of new items

View Source client/ui/abstract/container.js, line 194

this

# setLabelAlign(position)

Set the label alignment of all the container's fields

Parameters:
Name Type Default Description
position string left

"left" (default) | "right"

View Source client/ui/abstract/container.js, line 630

this

# setLabelPosition(position)

Set the label position of all the container's fields

Parameters:
Name Type Default Description
position string left

"left" (default) | "top" | "right" | "bottom"

View Source client/ui/abstract/container.js, line 536

this

# setLabelSize(size)

Set the label size of all the container's fields

Parameters:
Name Type Default Description
size string 1/3

"1/4" | "1/3" (default) | "1/2" | "2/3" | "3/4"

View Source client/ui/abstract/container.js, line 581

this

# showItem(itemIndex, animationopt)

For multiview containers, show only a specific item of the container, given by index

Parameters:
Name Type Attributes Description
itemIndex number
animation object | string <optional>

Optional animation when displaying the item

View Source client/ui/abstract/container.js, line 120

this

# showItemByClass(className, animationopt)

For multiview containers, show only a specific item of the container, given by CSS class

Parameters:
Name Type Attributes Description
className string
animation object | string <optional>

Optional animation when displaying the item

View Source client/ui/abstract/container.js, line 152

this

# showItemById(id, animationopt)

For multiview containers, show only a specific item of the container, given by id

Parameters:
Name Type Attributes Description
id string
animation object | string <optional>

Optional animation when displaying the item

View Source client/ui/abstract/container.js, line 139

this

# updateLayout()

Update layout of the component with its new config parameters. It affects:

  • the size properties
  • the position

It can be useful to update the layout for example when:

  • the global window (screen) is resized
  • the parent container is resized
  • a parameter used in the function to compute a width or height has changed

Note: the layout is updated only if the Element is connected to the DOM.

View Source client/ui/abstract/container.js, line 511

this

Example
myComponent.updateLayout()

# validate() → {boolean}

Validate all the container's fields and return the result

View Source client/ui/abstract/container.js, line 423

true if all fields have passed the validation

boolean