Adding and removing elements - Demonstration

Click any of the form items and buttons corresponding to the clicked item's context will appear on the upper left corner of the screen.

If you want to remove elements, press the (x) sign in the item's title.

The structure of the form is described below. The items with the (+) sign can be added

  • Retailers
    • Retailer (+)
      • Board of supervisors
        • Supervisor (+)
        • Meeting (+)
          • Subject (+)
      • Division (+)
 
Retailers
Retailers
Retailer
Retailer
Board Of Supervisors
Board Of Supervisors
Supervisor
First Name
50
Last Name
50
Joining Date
Meeting
Meeting
Date
Time
Subject
100
Conclusion
Division
division Number
City
50
Foundation Year
Number Of Employees
Net Income
XML output

        
 
Add buttons Controller

If you want to change the behavior of the control that displays the add buttons, you can do it using the form below:

Depth
Count empty containers
12
Adding and removing elements - Description

MForm displays a tree of elements - if the schema permits, some of these elements may be removed, other may have subelements added.

When it comes to removing, the task is easy - there is a removal button near the element. Pressing this button removes the element on condition that after removing this element the amount of these element's siblings would not be lower than the MinOccurs property.

But with adding elements, the task is a little bit more complicated. The buttons to add elements are kept in their elements parents. In HTML they are in the div with BC (button container) class. It is absolutely possible to use these buttons, however mixing adding new elements with editing the existing ones is not favourable.

This is why in the defualt styles the div.BC selector is set to display: none.

To display the 'add' buttons in one place, the TabButtons control can be used.

The control works in such a way, that clicking an element on the form forces the control to display 'add' buttons that are bound to the clicked element.

The control contains a Depth property (the default value of this property is 2), which informs how deep should the control go in displaying parent's buttons:

  • 1 - display only clicked element's buttons
  • 2- display clicked element's and its parent's buttons)
  • 3- display clicked element's and its parent's and grandparent's buttons)
  • etc ...

Because some elements do not have associated buttons (i.e. leaf elements that cannot have any children), setting the Depth property to 3 will not necessarily mean that 3 button containers will be displayed. To count only non-empty button containers, one can set the CountEmptyContainers property to false.