⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formitem.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
/*
 * 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	FormItem//// An Item that can participate in a DynamicForm, managing some value.// <P>// FormItems are never directly created, instead, FormItem descriptors are passed to a// DynamicForm.  See the +link{DynamicForm} documentation for details.//// @treeLocation Client Reference/Forms/Form Items// @visibility external//<// XXX this should be a subclass of "TableItem" or something else that understands width,// height, rowSpan, colSpan et al, but is not necessary a form item, to allow the form layout// code to be factored out and used elsewhere.isc.ClassFactory.defineClass("FormItem");// Copy across the canvas method to generate DOM IDs for the various elements we will be// creatingisc.FormItem.addMethods({_getDOMID:isc.Canvas.getPrototype()._getDOMID});isc.FormItem.addClassMethods({        //> @classMethod FormItem.create()    // FormItem.create() should never be called directly, instead, create a +link{DynamicForm}    // and specify form items via +link{DynamicForm.items,form.items}.    //    // @visibility external    //<    // Log a warning if called directly    create : function (A,B,C,D,E,F,G,H,I,J,K,L,M) {        this.logWarn(            "Unsupported call to " + this.getClassName() + ".create(). FormItems must be created " +            "by their containing form. To create form items, use the 'items' property of a DynamicForm " +            "instance. See documentation for more details."        );        // If we're passed properties combine them into a single raw object - if this is then        // assigned to a form's "items" attribute the developer will likely get the expected        // behavior.        // (No need to call Super)        return isc.addProperties({}, A,B,C,D,E,F,G,H,I,J,K,L,M);    },    // getNewTagID() -- a method to broker out IDs for the form element tags, if no name is    // specified for the form element    // (If a name is specified we'll use that instead)    getNewTagID : function () {        if (this._currentTagIDNumber == null) this._currentTagIDNumber = 0;        this._currentTagIDNumber += 1;        return "isc_FormItemElement_ID_" + this._currentTagIDNumber;    },        // setElementTabIndex()    // Given a DOM element (a form item element), and a tabIndex, update the tabIndex on    // the appropriate element.    setElementTabIndex : function (element, tabIndex) {        // Set the tabIndex property on the element        element.tabIndex = tabIndex;                // In mozilla setting a tabIndex to -1 is not sufficient to remove it from the        // page's tab order -- update the 'mozUserFocus' property as well to achieve this        // if we're passed a desired tabIndex less than zero (or revert this property if        // necessary from a previous exclusion from the page's tab order)                if (isc.Browser.isMoz) {            element.style.MozUserFocus = (tabIndex < 0 ? "ignore" : "normal");        }    },                _aboutToFireNativeElementFocus : function (item) {        if (!isc.Browser.isIE) return;        var activeElement = this.getActiveElement();                if (activeElement && activeElement.tagName == null) activeElement = null;                // Note: this will work for elements in the DOM that are not part of ISC form items.        if (activeElement &&             ((activeElement.tagName.toLowerCase() == this._inputElementTagName &&               activeElement.type.toLowerCase() == this._textElementType) ||               activeElement.tagName.toLowerCase() == this._textAreaElementTagName))         {            // IE proprietary API            var range = activeElement.createTextRange();            range.execCommand("Unselect");        }    },        // Helper method to determine if the item passed in is text based    _textBasedItem : function (item, checkForPopUp) {        if (isc.isA.FormItem(item)) item = item.getClassName();                if (!this._textClassNames) {            this._textClassNames = {                text:true,                TextItem:true,                textItem:true,                textArea:true,                TextAreaItem:true,                textAreaItem:true            }            this._popUpClassNames = {                popUpTextArea:true,                PopUpTextAreaItem:true,                popUpTextAreaItem:true            }        }                return this._textClassNames[item] || (!checkForPopUp || this._popUpClassNames[item]);    },        // Native handlers to be applied to elements written into the DOM    // --------------------------------------------------------------------------------------        // Focus/blur handelers to be applied to Form item elements.    // Applied directly to the element, so we need to determine which item we are a part of    // and call the appropriate focus/blur handler method on that item.    _nativeFocusHandler : function () {                //!DONTCOMBINE        if (!window.isc || !isc.DynamicForm) return;        var element = this,            itemInfo = isc.DynamicForm._getItemInfoFromElement(element),            item = itemInfo.item;                        if (item && item.isDisabled()) {            element.blur();                    return;        }                    if (item) {            return item._nativeElementFocus(element, item);        }    },        _nativeBlurHandler : function () {        // Check for blur being fired on page unload (when the isc object is out of scope)        //!DONTCOMBINE        if (!window.isc) return;        var element = this,            itemInfo = isc.DynamicForm._getItemInfoFromElement(element),            item = itemInfo.item;            if (item && item.hasFocus) {                return item._nativeElementBlur(element, item);            }    },        // IE specific handler for oncut / onpaste    _nativeCutPaste : function () {        if (!window.isc) return;        var element = this,            itemInfo = isc.DynamicForm._getItemInfoFromElement(element),            item = itemInfo.item;        if (item && item.hasFocus) {            return item._nativeCutPaste(element, item);        }    },        // For some form items we make use of the native onchange handler.    // This is a single function that will be applied directly to elements as a change handler    // Currently used by the nativeSelectItem class and the checkboxItem class    _nativeChangeHandler : function () {                //!DONTCOMBINE        if (!window.isc || !isc.DynamicForm) return;                    var element = this,            itemInfo = isc.DynamicForm._getItemInfoFromElement(element),            item = itemInfo.item;        if (item) return item._handleElementChanged();    },            // Focus / blur handlers applied directly to icons    _nativeIconFocus : function () {        //!DONTCOMBINE        var element = this,            itemInfo = isc.DynamicForm._getItemInfoFromElement(element),            item = itemInfo.item,            iconID = itemInfo.overIcon;        if (item) {                        if (item.iconIsDisabled(iconID)) element.blur();            else return item._iconFocus(iconID, element);        }    },        _nativeIconBlur : function () {         //!DONTCOMBINE        if (!window.isc) return;                var element = this,            itemInfo = isc.DynamicForm._getItemInfoFromElement(element),            item = itemInfo.item,            iconID = itemInfo.overIcon;        if (item && !item.iconIsDisabled(iconID)) return item._iconBlur(iconID, element);    },    // Native click handler for icons can just return false. This will cancel navigation.    // We will fire icon.click() via the standard DynamicForm.handleClick method        _nativeIconClick : function () {        return false;    },        // Helper method to return a string formatted for display as the title attribute of an    // error icon.          getErrorPromptString : function (errors) {        var errorString = "";        if (!isc.isAn.Array(errors)) errors = [errors];        for (var i =0; i< errors.length; i++) {            errorString += (i > 0 ? (isc.Browser.isMoz ? "  " : "\n") : "") + errors[i];        };        return errorString;    }});isc.FormItem.addClassProperties({        _inputElementTagName : "input",    _textElementType : "text",    _textAreaElementTagName : "textarea"});isc.FormItem.addProperties({    // Basics    // ---------------------------------------------------------------------------------------    //> @type FormItemType    // DynamicForms automatically choose the FormItem type for a field based on the    // <code>type</code> property of the field.  The table below describes the default FormItem    // chosen for various values of the <code>type</code> property.    // <P>    // You can also set +link{FormItem.editorType,field.editorType} to the classname of a    // +link{FormItem} to override this default mapping.    //    // @value "text"    Rendered as a +link{class:TextItem}, unless the lenght of the field (as    // specified by +link{attr:dataSourceField.length} attribute) is larger than the value    // specified by +link{attr:dynamicForm.longTextEditorThreshold}, a    // +link{class:TextAreaItem} is shown.    //    // @value "boolean"  Rendered as a +link{class:CheckBoxItem}    //    // @value "integer"  Same as <code>text</code> by default.      //                   Consider setting editorType:+link{SpinnerItem}.    // @value "float"    Same as <code>text</code> by default.      //                   Consider setting editorType:+link{SpinnerItem}.    // @value "date"     Rendered as a +link{class:DateItem}    // @value "time"     Rendered as a +link{class:TimeItem}    // @value "enum"     Rendered as a +link{class:SelectItem}.  Also true for any field that    //                   specifies a +link{formItem.valueMap}.      //                   Consider setting editorType:+link{ComboBoxItem}.    // @value "sequence" Same as <code>text</code>    // @value "link"     If +link{dataSourceField.canEdit}<code>:false</code> is set on the field,    // the value is rendered as a +link{class:LinkItem}.  Otherwise the field is rendered as a    // +link{class:TextItem}.    //    // @value "image"        // @value "imageFile"    // @value "binary"   Rendered as a +link{class:UploadItem}    //    // @see attr:FormItem.type    // @see type:FieldType    // @visibility external    //<        //> @attr formItem.type (FormItemType : "text" : [IR])    // The DynamicForm picks a field renderer based on the type of the field (and sometimes other    // attributes of the field).    //    // @see type:FormItemType    // @see type:FieldType    // @group appearance    // @visibility external    //<     //> @attr formItem.editorType (FormItem class : null : [IR])    // Name of the FormItem to use for editing, eg "TextItem" or "SelectItem".    // <P>    // The type of FormItem to use for editing is normally derived automatically from    // +link{formItem.type,field.type}, which is the data type of the field, by the rules    // explained +link{type:FormItemType,here}.    //    // @see type:FormItemType    // @see type:FieldType    // @group appearance    // @visibility external    //<    //> @attr formItem.name              (identifer : null : IRW)	// Name for this form field.    // <br><br>    // The FormItem's name determines the name of the property it edits within the form.    //     // @group basics    // @visibility external    //<    //> @attr formItem.title             (String : null : IRW)	// User visible title for this form item.    // 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -