📄 dynamicform.js
字号:
// @group submitting // @visibility external //< //> @attr dynamicForm.method (FormMethod : isc.DynamicForm.POST : [IRW]) // The mechanism by which form data is sent to the action URL. See FormMethod type // for details. // <p> // <b>NOTE:</b> this is used only in the very rare case that a form is used to submit data // directly to a URL. Normal server contact is through // +link{group:dataBoundComponentMethods,DataBound Component Methods}. // @group submitting // @visibility external //< method:isc.DynamicForm.POST, //> @attr dynamicForm.encoding (Encoding : DynamicForm.NORMAL : IRWA) // encoding for the form, use MULTIPART_ENCODING for file upload forms // @group submitting // @visibility external //< encoding:isc.DynamicForm.NORMAL_ENCODING, //> @attr dynamicForm.canSubmit (boolean : false : IRWA) // Governs whether this form will be used to perform a standard HTML form submission. // Note that if true, +link{DynamicForm.submit()} will perform a native HTML submission // to the specified +link{DynamicForm.action} URL.<br> // Wherever possible we strongly recommend using the // +link{group:dataBoundComponentMethods,DataBound Component Methods} to send data to // the server as they provide a far more sophisticated interface, with built in // options for server validation, required fields, etc.<br> // @group submitting // @visibility external //< // Defaulted to false, as we usually do not want direct submission behaviour. // Note: if true, and saveData() is called, the rpcManager code will perform its request // as a direct submission to the action URL by setting request.directSubmit // whether to write the <form> tag writeFormTag:true, //> @attr dynamicForm.saveOnEnter (boolean : false :IRW) // If <code>true</code>, when the user hits the Enter key while focussed in a text-item in // this form, we automatically submit the form to the server using the // +link{dynamicForm.submit()} method. // @visibility external // @group submitting //< //> @attr dynamicForm.autoSendTarget (boolean : false : IRWA) // Should we send the form target name to the server automatically? // @group submitting //< // if autoSendTarget is true, we automatically add a hidden field to the form that tells the // server the name of the target the form was submitting to. This is useful for // reauthentication purposes. //> @attr dynamicForm.autoSendTargetFieldName (string : "__target__" : IRWA) // Name of the field in which the form target will be set // @group submitting //< autoSendTargetFieldName:"__target__", // useNativeSelectItems // Determines whether items of type "select" or "SelectItem" should be rendered as // our ISC SelectItems or NativeSelectItems useNativeSelectItems:false, hideUsingDisplayNone: isc.Browser.isMoz && isc.Browser.isMac});// add default methodsisc.DynamicForm.addMethods({//---------------------------// Data initialization//---------------------------//> @method dynamicForm.initWidget() (A)// initialize the form object //// initializes th list of fields// sets up the data (if specified)// clears the errors array//// @param [all arguments] (object) objects with properties to override from default//<initWidget : function () { if (isc._traceMarkers) arguments.__this = this; // call the superclass function this.Super("initWidget",arguments); // allow for fields instead of items specification if (this.fields && this.items == null) this.items = this.fields; // If we have a set of 'defaultItems' in an array, and the developer hasn't set the items // property, use the defaultItems array instead. // Notes: // - The 'defaultItems' property would typically be set on the instance prototype this class // (or subclasses). // - In each instance we *copy* the defaultItems array into this.items, and avoid manipulating // it directly. This means specific instances will not write properties out into the // instance prototype's 'defaultItems' array (which would happen if manipulated directly as // it is passed by reference to each instance, so all instances point to the same object) // When creating a DynamicForm subclass, for which each instance should show a specific set // of items by default, the defaultItems property should be set on the instance prototype. // Settting the items property directly on the instance prototype is a bad idea as each // instance will then point to the same items array. // (Used in Editor.js) if (this.defaultItems != null && this.items == null) { this.items = []; for (var i = 0; i < this.defaultItems.length; i++) { this.items[i] = isc.addProperties({}, this.defaultItems[i]); } } // Default values to an empty list. if (this.values == null) this.values = {}; // initialize the list of fields, defaulting to an empty list // Note: We set up the items (and set their values / eval defaultDynamicValue) at Form init // time so that a developer can define a form and then work with the items before drawing the // form using the standard form item APIs. // This is in contrast to the approach used (for example) in the ListGrid, where the component // parts of the LG (header, body, etc.) are not created until draw in order to minimize the // cost associated with changing the dataSource / data /etc. while the widget is undrawn. this.setItems(this.items ? this.items : [], true); // If we've been marked as disabled explicitly disable all form items. if (this.isDisabled()) { this.setDisabled(true); } //>ValuesManager // If we have a 'valuesManager' property, at this point ensure we are properly linked to // it. if (this.valuesManager != null) { var vM = this.valuesManager; // clear out the property - it will be re-added as part of 'addMember()' on the VM this.valuesManager = null; if (isc.isA.ValuesManager(vM)) { vM.addMember(this); } else if (isc.isA.ValuesManager(window[vM])) { window[vM].addMember(this); // If it's a string, create a new VM with that ID; } else if (isc.isA.String(vM)) { isc.ValuesManager.create({ ID:vM, members:[this] }); } else { this.logWarn("Form initialized with invalid 'valuesManager' property:" + isc.Log.echo(vM) + ", clearing this property out"); } } //<ValuesManager // intialize the form errors, defaulting to an empty list this.setErrors(this.errors ? this.errors : {}); // initialize the form values, via 'setValues()' // this automatically remembers the old values for us as well this.setValues(this.values, true); },_destroyItems : function (items) { if (!items) return; if (!isc.isA.FormItem(items[0])) return; items.map("destroy");},destroy : function () { if (this.valuesManager) this.valuesManager.removeMember(this); this._destroyItems(this.items); this.Super("destroy", arguments);},// Override 'setHandleDisabled' to disable / enable all itemssetHandleDisabled : function (disabled) { this.Super("setHandleDisabled", arguments); var items = this.getItems(); for (var i = 0; i < items.length; i ++) { items[i].updateDisabled(); }},//> @method dynamicForm.applyFieldDefaults()// @group data// Selects the appropriate form item type for fields if not specified,// based on schema information.//<applyFieldDefaults : function (fields) { if (fields == null) return; for (var i = 0; i < fields.length; i++) { var field = fields[i]; // This null check will avoid JS errors if someone defines an array of fields with // a trailing comma in IE if (field == null) return; }},//> @method dynamicForm.getEditorType() ([A])//// Returns the form item type (Class Name) to be created for some field.<br>// By default <code>field.editorType</code> will be used if present - otherwise backs off to// deriving the appropriate form item type from the data type of the field (see// +link{type:FormItemType} for details.//// @group editing//// @param field (object) field definition for which we are deriving form item type.// @return (string) form item type for the field// @visibility external //<getEditorType : function (field) { return isc.DynamicForm.getEditorType(field, this);},//> @method dynamicForm.setItems()// Synonym for +link{DynamicForm.setFields()}//// @group elements// @param itemList (Array of objects) list of new items to show in the form// @visibility external//<setItems : function (itemList, firstInit) { // mark any items which had explicitly defined types, so we don't override them with our logic // for picking default types if (itemList != null) { for (var i = 0; i < itemList.length; i++) { if (itemList[i] == null) { this.logWarn("Encountered empty entry in items array - removing this entry.") itemList.removeAt(i); i -= 1; continue; } } } // get field data by binding to a DataSource, if we were provided one. NOTE we do this first // because the returned list of items may be a new list itemList = this.bindToDataSource(itemList); //this.logWarn("itemList is : " + this.echo(itemList) + // ", this.items is : " + this.echo(this.items) + this.getStackTrace()); if (!itemList) itemList = []; // If the itemList passed in is the same array object as this.items, duplicate it, as // the removeItems call (below) will clear out that array. else if (itemList == this.items) itemList = itemList.duplicate(); // remove all existing items (destroy FormItem objects we created) if (this.items != null && this.items.length > 0 && !firstInit) this.removeItems(this.items); this._addItems(itemList, null, true, firstInit);},//> @method dynamicForm.setFields()// Set the +link{dynamicForm.fields, items} for this DynamicForm. // Takes an array of item definitions, which will be converted to +link{FormItem}s and // displayed in the form.<br>// Note: Do not attempt to create +link{FormItem} instances directly. This method should be// passed the raw properties for each item only.//// @group elements// @param itemList (Array of objects) list of new items to show in the form// @visibility external//<setFields : function (fieldList) { this.setItems(fieldList);},//> @method dynamicForm.getFields()// Method to retrieve the +link{dynamicForm.fields, items} for this DynamicForm. //// @group elements// @param itemList (Array of objects) list of new items to show in the form// @visibility external//<getFields : function () { return this.items;},//> @method dynamicForm.getItems()// Method to retrieve the +link{dynamicForm.fields, items} for this DynamicForm. //// @group elements// @param itemList (Array of objects) list of new items to show in the form// @visibility external//<getItems : function () { return this.items;},// Override visibleAtPoint to return true if we have any items contained in containerWidgets// which would be visible at the specified point.visibleAtPoint : function (x, y, withinViewport, ignoreWidgets) { if (this.invokeSuper(isc.DynamicForm, "visibleAtPoint", x,y,withinViewport,ignoreWidgets)) return true; var items = this.items || [], containerWidgets = {}, focusItemIndex = items.indexOf(this.getFocusItem()); for (var i = -1; i < items.length; i++) { var itemIndex = i; if (i == -1) { itemIndex = focusItemIndex; // avoid checking the focus item twice } else if (itemIndex == focusItemIndex) continue;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -