X-Git-Url: http://git.ithinksw.org/extjs.git/blobdiff_plain/25ef3491bd9ae007ff1fc2b0d7943e6eaaccf775..6a7e4474cba9d8be4b2ec445e10f1691f7277c50:/src/widgets/form/BasicForm.js diff --git a/src/widgets/form/BasicForm.js b/src/widgets/form/BasicForm.js index 973b7c11..7aee4dbf 100644 --- a/src/widgets/form/BasicForm.js +++ b/src/widgets/form/BasicForm.js @@ -1,6 +1,6 @@ /*! - * Ext JS Library 3.0.3 - * Copyright(c) 2006-2009 Ext JS, LLC + * Ext JS Library 3.2.0 + * Copyright(c) 2006-2010 Ext JS, Inc. * licensing@extjs.com * http://www.extjs.com/license */ @@ -34,50 +34,51 @@ * @param {Mixed} el The form element or its id * @param {Object} config Configuration options */ -Ext.form.BasicForm = function(el, config){ - Ext.apply(this, config); - if(Ext.isString(this.paramOrder)){ - this.paramOrder = this.paramOrder.split(/[\s,|]/); - } - /** - * @property items - * A {@link Ext.util.MixedCollection MixedCollection) containing all the Ext.form.Fields in this form. - * @type MixedCollection - */ - this.items = new Ext.util.MixedCollection(false, function(o){ - return o.getItemId(); - }); - this.addEvents( - /** - * @event beforeaction - * Fires before any action is performed. Return false to cancel the action. - * @param {Form} this - * @param {Action} action The {@link Ext.form.Action} to be performed - */ - 'beforeaction', - /** - * @event actionfailed - * Fires when an action fails. - * @param {Form} this - * @param {Action} action The {@link Ext.form.Action} that failed - */ - 'actionfailed', +Ext.form.BasicForm = Ext.extend(Ext.util.Observable, { + + constructor: function(el, config){ + Ext.apply(this, config); + if(Ext.isString(this.paramOrder)){ + this.paramOrder = this.paramOrder.split(/[\s,|]/); + } /** - * @event actioncomplete - * Fires when an action is completed. - * @param {Form} this - * @param {Action} action The {@link Ext.form.Action} that completed + * A {@link Ext.util.MixedCollection MixedCollection} containing all the Ext.form.Fields in this form. + * @type MixedCollection + * @property items */ - 'actioncomplete' - ); - - if(el){ - this.initEl(el); - } - Ext.form.BasicForm.superclass.constructor.call(this); -}; + this.items = new Ext.util.MixedCollection(false, function(o){ + return o.getItemId(); + }); + this.addEvents( + /** + * @event beforeaction + * Fires before any action is performed. Return false to cancel the action. + * @param {Form} this + * @param {Action} action The {@link Ext.form.Action} to be performed + */ + 'beforeaction', + /** + * @event actionfailed + * Fires when an action fails. + * @param {Form} this + * @param {Action} action The {@link Ext.form.Action} that failed + */ + 'actionfailed', + /** + * @event actioncomplete + * Fires when an action is completed. + * @param {Form} this + * @param {Action} action The {@link Ext.form.Action} that completed + */ + 'actioncomplete' + ); + + if(el){ + this.initEl(el); + } + Ext.form.BasicForm.superclass.constructor.call(this); + }, -Ext.extend(Ext.form.BasicForm, Ext.util.Observable, { /** * @cfg {String} method * The request method to use (GET or POST) for form actions if one isn't supplied in the action options. @@ -277,15 +278,20 @@ new Ext.FormPanel({ e.stopEvent(); }, - // private - destroy: function() { - this.items.each(function(f){ - Ext.destroy(f); - }); - if(this.el){ - this.el.removeAllListeners(); - this.el.remove(); + /** + * Destroys this object. + * @private + * @param {Boolean} bound true if the object is bound to a form panel. If this is the case + * the FormPanel will take care of destroying certain things, so we're just doubling up. + */ + destroy: function(bound){ + if(bound !== true){ + this.items.each(function(f){ + Ext.destroy(f); + }); + Ext.destroy(this.el); } + this.items.clear(); this.purgeListeners(); }, @@ -434,8 +440,9 @@ myFormPanel.getForm().submit({ * @return {BasicForm} this */ submit : function(options){ + options = options || {}; if(this.standardSubmit){ - var v = this.isValid(); + var v = options.clientValidation === false || this.isValid(); if(v){ var el = this.el.dom; if(this.url && Ext.isEmpty(el.action)){ @@ -493,6 +500,12 @@ myFormPanel.getForm().submit({ // private beforeAction : function(action){ + // Call HtmlEditor's syncValue before actions + this.items.each(function(f){ + if(f.isFormField && f.syncValue){ + f.syncValue(); + } + }); var o = action.options; if(o.waitMsg){ if(this.waitMsgTarget === true){ @@ -538,15 +551,23 @@ myFormPanel.getForm().submit({ * {@link Ext.grid.Column#dataIndex dataIndex}, {@link Ext.form.Field#getName name or hiddenName}). * @return Field */ - findField : function(id){ + findField : function(id) { var field = this.items.get(id); - if(!Ext.isObject(field)){ - this.items.each(function(f){ - if(f.isFormField && (f.dataIndex == id || f.id == id || f.getName() == id)){ - field = f; - return false; + + if (!Ext.isObject(field)) { + //searches for the field corresponding to the given id. Used recursively for composite fields + var findMatchingField = function(f) { + if (f.isFormField) { + if (f.dataIndex == id || f.id == id || f.getName() == id) { + field = f; + return false; + } else if (f.isComposite) { + return f.items.each(findMatchingField); + } } - }); + }; + + this.items.each(findMatchingField); } return field || null; }, @@ -558,7 +579,7 @@ myFormPanel.getForm().submit({ * @return {BasicForm} this */ markInvalid : function(errors){ - if(Ext.isArray(errors)){ + if (Ext.isArray(errors)) { for(var i = 0, len = errors.length; i < len; i++){ var fieldError = errors[i]; var f = this.findField(fieldError.id); @@ -566,7 +587,7 @@ myFormPanel.getForm().submit({ f.markInvalid(fieldError.msg); } } - }else{ + } else { var field, id; for(id in errors){ if(!Ext.isFunction(errors[id]) && (field = this.findField(id))){ @@ -574,6 +595,7 @@ myFormPanel.getForm().submit({ } } } + return this; }, @@ -634,10 +656,33 @@ myFormPanel.getForm().submit({ return Ext.urlDecode(fs); }, - getFieldValues : function(){ - var o = {}; - this.items.each(function(f){ - o[f.getName()] = f.getValue(); + /** + * Retrieves the fields in the form as a set of key/value pairs, using the {@link Ext.form.Field#getValue getValue()} method. + * If multiple fields exist with the same name they are returned as an array. + * @param {Boolean} dirtyOnly (optional) True to return only fields that are dirty. + * @return {Object} The values in the form + */ + getFieldValues : function(dirtyOnly){ + var o = {}, + n, + key, + val; + this.items.each(function(f) { + if (dirtyOnly !== true || f.isDirty()) { + n = f.getName(); + key = o[n]; + val = f.getValue(); + + if(Ext.isDefined(key)){ + if(Ext.isArray(key)){ + o[n].push(val); + }else{ + o[n] = [key, val]; + } + }else{ + o[n] = val; + } + } }); return o; }, @@ -682,7 +727,6 @@ myFormPanel.getForm().submit({ return this; }, - /** * Removes a field from the items collection (does NOT remove its markup). * @param {Field} field @@ -743,4 +787,4 @@ myFormPanel.getForm().submit({ }); // back compat -Ext.BasicForm = Ext.form.BasicForm; \ No newline at end of file +Ext.BasicForm = Ext.form.BasicForm;