📄 dynamicform.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
//> @class DynamicForm//// The DynamicForm manages a collection of FormItems which represent user input controls. The// DynamicForm provides layout, value management, validation and databinding for the controls// it manages.// <P>// To create a DynamicForm, set +link{dynamicForm.fields} to an Array of Objects describing the// FormItems you want to use. For example:// <pre>// isc.DynamicForm.create({// fields:[// {name:"userName", type:"text"}, // creates a TextItem// {name:"usState", type:"select"} // creates a SelectItem// ]// })// </pre>// The item <code>name</code> is an identifier for the item that must be unique just within// this form. It is used:// <ul>// <li> as the property name under which the item's value is stored in the form (the form's// current values are accessible as +link{dynamicForm.getValues,form.getValues()}// <li> when retrieving the FormItem's current value (via// +link{dynamicForm.getValue,form.getValue()}) // <li> to retrieve the item itself via +link{dynamicForm.getItem(),form.getItem()}// </ul>// The item <code>type</code> controls what kind of FormItem is created. See// +link{type:FormItemType}.// <P>// The +link{formItem.title,title} and +link{formItem.defaultValue,defaultValue} are also// commonly specified. All FormItems share a common set of properties for controlling// +link{group:formLayout,form layout}. Other properties common to all FormItems are// documented on the +link{FormItem} class, and properties specific to particular FormItems are// documented on the respective FormItems. // <P>// NOTE: For very simple forms consisting of exactly one item, you still use a DynamicForm.// See the "fontSelector" form in the +explorerExample{toolstrip,Toolstrip example}.//// @implements DataBoundComponent // @treeLocation Client Reference/Forms// @visibility external//<// create the form as a descendant of the Canvasisc.ClassFactory.defineClass("DynamicForm", "Canvas");// Synonym for use by ValuesManagers working with distributed 'FormLayouts'isc.addGlobal("FormLayout", isc.DynamicForm);//> @groupDef items// Manipulating the items that belong to a form.// <BR><br>// An item manages an atomic value (eg a String, Number, Date, etc) that appears as one of the// properties in the overall form's values. Some items exist purely for layout or appearance// purposes (eg SpacerItem) and do not manage a value.// @title Form Items// @visibility external//<//> @groupDef tableLayout// Manipulating the values stored in the form.// @visibility external//<//> @groupDef values// Manipulating the values stored in the form.// @visibility external//<//> @groupDef valueMap// Mapping from stored values to user-visible values// @visibility external//<//> @groupDef validation// Validation// @visibility external//<//> @groupDef formTitles// Properties that affect form item title placement and styling.// @title Form Titles// @visibility external//<//> @groupDef errors// Validation errors and how they are shown// @visibility external//<//> @groupDef submitting// Direct submission of forms to a target URL// <P>// <b>NOTE:</b> directly submitting forms is only done for specialized purposes, such as// integration with certain legacy systems. Normal form usage contacts the server via // +link{group:dataBoundComponentMethods,DataBound Component Methods}, through the RPCManager system.// @visibility external//<//> @groupDef elements// Manipulating native form elements//<// add constantsisc.DynamicForm.addClassProperties({ //> @type FormMethod // Form METHOD parameters - how the form fields are submitted to the server GET:"GET", // @value isc.DynamicForm.GET GET request -- URL encoding (~4K max) POST:"POST", // @value isc.DynamicForm.POST POST request -- separate field encoding (no max) // @visibility external // @group submitting //< //> @type Encoding // Form encodying types - these translate to Form ENCTYPE parameters. // @value DynamicForm.NORMAL normal form encoding ("application/x-www-form-urlencoded") NORMAL: "normal", // @value DynamicForm.MULTIPART form encoding for forms with INPUT file elements, that is, forms // that upload files ("multipart/form-data") MULTIPART: "multipart", // @group submitting // @visibility external //< // NOTE: EncodingTypes has the values that we actually write into the form in HTML. //> @type EncodingTypes // Form ENCTYPE parameters - how data is encoded when sent to the server. // See: http://www.w3.org/TR/html4/interact/forms.html#adef-enctype // @group submitting // normal form encoding NORMAL_ENCODING: "application/x-www-form-urlencoded", // multipart encoding for file upload MULTIPART_ENCODING: "multipart/form-data", //< // Attributes written into containers for form items / form item elements _containsItem : "_containsItem", _itemPart : "_itemPart", // Options for the itemPart setting _element : "_element", _textBoxString : "_textBox", _controlTableString : "_controlTable", _title : "_title" });isc.DynamicForm.addProperties({ // Basic Definition: items and values // -------------------------------------------------------------------------------------------- //> @attr dynamicForm.items (Array of FormItem Properties : null : [IRW]) // Synonym for +link{attr:dynamicForm.fields} // // @see attr:dynamicForm.fields // @group items // @setter setItems() // @visibility external //< //> @attr dynamicForm.fields (Array of FormItem Properties : null : [IRW]) // An array of field objects, specifying the order, layout, and types of each field in the // DynamicForm. // <p> // When both <code>dynamicForm.fields</code> and <code>dynamicForm.dataSource</code> are // set, <code>dynamicForm.fields</code> acts as a set of overrides as explained in // +link{attr:DataBoundComponent.fields}. // <P> // See +link{group:formLayout,Form Layout} for information about how flags specified on // the FormItems control how the form is laid out. // // @see class:FormItem // @setter setFields() // @group items // @visibility external //< //> @attr dynamicForm.defaultItems (Array of FormItem Properties : null : [ARW]) // An array of FormItem objects, defining the default set of elements this form // creates. (Typically set at a class level on the instance prototype). // @group items //< // NOTE: not external; used for making specialized form subclasses //> @attr dynamicForm.values (Object : null : [IRW]) // An Object containing the initial values of the form as properties, where each // propertyName is the name of a +link{items,form item} in the form, and each property // value is the value held by that form item. // <P> // The form's values may contain values that are not managed by any FormItem, and these // values will be preserved and available when the form values are subsequently retrieved // via +link{getValues()}. // <P> // Providing values on initialization is equivalent to calling +link{setValues()}. // <P> // As the user manipulates form items to change values, change events fire // +link{formitem.change,on the items} and // +link{dynamicForm.itemChange,on the form as a whole}. // <P> // Note that form values are logical values, for example, the value of a +link{DateItem} is // a JavaScript Date object, not a String, even if the user enters the date via a text // input. Likewise the value of a +link{TextItem} or +link{CheckboxItem} that started out // null remains null until the user changes it; the value will not be automatically // converted to the null string ("") or false respectively, as happens with native HTML // elements. // // @group formValues // @visibility external //< // Table Layout // -------------------------------------------------------------------------------------------- //> @groupDef formLayout // <b>FormItem Placement in Columns and Rows</b> // <P> // With the default tabular layout mechanism, items are laid out in rows from left to // right until the number of columns, specified by +link{dynamicForm.numCols,form.numCols}, // is filled, then a new row is begun. Flags on FormItems, including // +link{FormItem.startRow,startRow}, +link{FormItem.endRow,endRow}, // +link{FormItem.colSpan,colSpan} and +link{FormItem.rowSpan,rowSpan}, control row and // column placement and spanning. // <P> // Note that the most common form items (TextItem, SelectItem, etc) take up <b>two</b> // columns by default: one for the form control itself, and one for it's title. The // default setting of +link{dynamicForm.numCols,form.numCols:2} will result in one TextItem // or SelectItem per row. // <P> // Note also that ButtonItems have both startRow:true and endRow:true by default. You must // set startRow and/or endRow to <code>false</code> on a ButtonItem in order to place a // button in the same row as any other item. // <P> // The log category "tablePlacement" can be enabled from the Developer Console to watch // items being placed. You can also set +link{dynamicForm.cellBorder,form.cellBorder:1} to // reveal the table structure for layout troubleshooting purposes. // <P> // <b>Row and Column Sizing</b> // <P> // +link{DynamicForm.colWidths} controls the widths of form columns. FormItems that have // "*" for +link{formItem.width} will fill the column. FormItems with a numeric width will // have that width in pixels regardless of the column's specified width, which may cause the // column to overflow as described under +link{DynamicForm.fixedColWidths}. // <P> // For row heights, the largest pixel height specified on any item in the row is taken as a // minimum size for the row. Then, any rows that have "*" or "%" height items will share // any height not taken up by fixed-sized items. // <P> // <b>Managing Overflow</b> // <P> // Forms often contain labels, data values, or instructional text which can vary in // size based on the skin, data values, or internationalization settings. There are a few // ways to deal with a form potentially varying in size: // <ol> // <li> Allow scrolling when necessary, using +link{Canvas.overflow,overflow:auto}, either // on the immediate form, or on some parent. // <li> Place the form in a Layout along with a component that can render any specified // size, such as a +link{ListGrid}. In this case, the Layout will automatically shrink the // grid in order to accomodate the form. // <li> Ensure that the form can always render at a designed minimum size by reducing // the number of cases of variable-sized text, and testing remaining cases across all // supported skins. For example, move help text into hovers on help icons, or clip // long text values at a maximum length and provide a hover to see the rest. // </ol> // // Several examples of Form Layout are available +explorerExample{formsLayout,here}. // // @treeLocation Client Reference/Forms // @title Form Layout // @visibility external //< //> @attr dynamicForm.itemLayout (FormLayoutType : "table" : IRWA) // Layout style to use with this form. // <P> // The default of "table" uses a tabular layout similar to HTML tables, but with much more // powerful control over sizing, item visibility and reflow, overflow handling, etc. // <P> // <code>itemLayout:"absolute"</code> allows absolute positioning of every form item. This // provides maximum flexibility in placement, with the following limitations:<ul> // <li> titles, which normally take up an adjacent cell, are not shown. Use // StaticTextItems to show titles // <li> no automatic reflow when showing or hiding items. +link{method:FormItem.setLeft()} // and +link{method:FormItem.setTop()} can be used for manual reflow. // <li> only pixel and percent sizes are allowed, no "*". Percent widths mean percentage // of the overall form size rather than the column size // <li> with different font styling or internationalized titles, items may overlap that did // not overlap in the skin used at design time // </ul> // // @group formLayout // @visibility absForm //< //itemLayout:"table", //> @attr dynamicForm.numCols (number : 2 : [IRW]) // The number of columns of titles and items in this form's layout grid. A title and // corresponding item each have their own column, so to display two form elements per // row (each having a title and item), you would set this property to 4. // // @group tableLayout // @visibility external //< numCols:2, //> @attr dynamicForm.fixedColWidths (boolean : false : IRW) // If true, we ensure that column widths are at least as large as you specify them. This
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -