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