EXTJS4 about setting all child controls in a form to the ReadOnly property

Source: Internet
Author: User

Before looking for a bunch of online, but those really can't use, and later thought about it, found that the main is the assumption that the Web provides only a layer of control, without regard to the layout of a slightly complex form case, here in the form of recursive implementation of all the controls in the form (grid and button must be excluded, Otherwise the error will be reported, if you find other controls will also report an error, please feedback to me, so as to perfect this code)

The code is simple, setformreadonly requires two parameters, one for the form, and one for the bool variable, indicating that you need to add the ReadOnly attribute to the form as a whole or to remove this property.

Because setreadonly simply sets the control to read-only or not read-only, it cannot change the color of the control, and does not make it possible for the user to see if it is read-only, so use Setfieldstyle to make the control set to read-only grayed out.

Setformreadonly is a program entry, which has an inline function setitemsreadonly, which is a recursive function that, as long as it finds its own properties items are not empty, recursively calls itself, in such a way that all child controls are set to ReadOnly.

In addition, the program has a Stateid attribute to judge, this judgment is used in the ReadOnly control to return to normal when a filter, usually its stateid is readonly, all skip, maintain its ReadOnly property, not to restore

function (Form, readOnly) {
    function (Items, readOnly) {
        Items.each (function(item) {
                    var childitems = Item.items;
                    if false)) {
                        Setitemsreadonly (ChildItems, readOnly);
                    Else {
                        if "button" "GridView")) {
                            if "ReadOnly")) {
                                return ;
                            }
                            Item.setreadonly (readOnly);
                            if (readOnly) {
                                Item.setfieldstyle ("background: #E6E6E6");
                            Else {
                                Item.setfieldstyle ("background: #FFFFFF");
                            }
                        }
                    }
                });
    }
    Setitemsreadonly (Form.items, readOnly);
}

EXTJS4 about setting all child controls in a form to the ReadOnly property

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.