JS small exercise code 2 page 1/2
Last Update:2018-12-08
Source: Internet
Author: User
Related Source code As follows:
1. beginformpanel. js (Role: Display forms in outer HTML files)
<SCRIPT>
VaR beginformpanel = ext. Extend (ext. Form. formpanel ,{
Constructor: function ()
{
Beginformpanel. superclass. constructor. Call
(
This,
{
Title: "myform (never streaking )",
Width: 418,
Height: 180,
Frame: True,
Labelwidth: 45,
Style: "margin-left: 250px ",
Defaulttype: "textfield ",
Defaults: {anchor: "95% "},
Items:
[
{
Fieldlabel: "name ",
Name: "name"
},
{
Fieldlabel: "Age ",
Name: "Age"
},
{
Fieldlabel: "gender ",
Name: "sex"
},
{
Fieldlabel: "Address ",
Name: "ADDR"
}
],
Buttons:
[
{
Text: "add"
},
{
Text: "modify"
},
{
Text: "delete"
}
],
Renderto: Ext. getbody ()
}
);
}
});
</SCRIPT>
2. beginpanel. js (function: Implementation of gridpanel and window and formpanel in window)
<SCRIPT>
/*************************** Formpanel ********** **************************************** ***/
VaR mywindowform = ext. Extend (ext. Form. formpanel ,{
Constructor: function ()
{
Mywindowform. superclass. constructor. Call
(
This,
{
Labelwidth: 45,
Defaulttype: "textfield ",
Defaults: {anchor: "93% "},
Style: "padding: 5px ",
Basecls: "X-plain ",
Items:
[
{
Fieldlabel: "name ",
Name: "name ",
Allowblank: false,
Blanktext: "The name cannot be blank! "
},
{
Fieldlabel: "Age ",
Name: "Age ",
Allowblank: false,
Vtype: "Age ",
Blanktext: "Age cannot be blank! "
},
{
Fieldlabel: "gender ",
Name: "sex ",
Allowblank: false,
Blanktext: "gender cannot be blank! "
},
{
Fieldlabel: "Address ",
Name: "ADDR ",
Allowblank: false,
Blanktext: "The address cannot be blank! "
}
]
}
);
},
Getvalues: function ()
{
If (this. getform (). isvalid ())
{
Return new Ext. Data. Record (this. getform (). getvalues ());
}
Else
{
Throw error ("Form Verification Failed! ");
}
},
Setvalues: function (record)
{
This. getform (). loadrecord (record );
},
Reset: function ()
{
This. getform (). Reset ();
}
});
/******************************* Window ****** *****************************/
VaR mywindow = ext. Extend (ext. Window ,{
Form: New mywindowform (),
Constructor: function ()
{
Mywindow. superclass. constructor. Call
(
This,
{
Title: "mywindow (never streaking )",
Width: 300,
Height: 185,
Frame: True,
Plain: True,
Modal: True,
Items: This. form,
Closable: false, // disable
Collapsible: True, // foldable
Buttons:
[
{
Text: "OK ",
Handler: This. onsubmitclick,
Scope: This
},
{
Text: "cancel ",
Handler: This. oncancelclick,
Scope: This
}
]
}
);
This. addevents ("Submit ");
},
Close: function ()
{
This. Hide ();
},
Onsubmitclick: function ()
{
/*
Try
{
This. fireevent ("Submit", this, this. Form. getvalues ());
}
Catch (error)
{
Ext. msg. Alert ("warning", "complete the information you need! ");
}
*/
This. fireevent ("Submit", this, this. Form. getvalues ());
This. Close ();
},
Oncancelclick: function ()
{
// If the scope attribute is not added, this. form is blank.
This. Form. Reset ();
This. Close ();
}
});