Changeset 233
- Timestamp:
- 05/10/07 20:34:29 (6 years ago)
- Files:
-
- 1 modified
-
jala/trunk/code/Form.js (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jala/trunk/code/Form.js
r232 r233 90 90 91 91 92 /** 93 * The default getter function for this form. Unless a getter 94 * is specified for the component, this function is called 95 * to retrieve the original value of a field. 96 * When called, the scope is set to the data object and 97 * the name of the element is the sole argument. 98 * @see jala.Form.Component.Input#getValue 99 * @type Function 100 */ 101 this.getter; // for doc purposes only 102 103 // that's where the value really is stored: 104 var getter = jala.Form.propertyGetter; 105 106 this.__defineGetter__("getter", function() { return getter; }); 107 this.__defineSetter__("getter", function(newGetter) { 108 if (newGetter instanceof Function) { 109 getter = newGetter; 110 } 111 }); 112 113 114 /** 115 * The default setter function for this form. Unless a getter 116 * is specified for the component, this function is called to 117 * store the a value of a field. 118 * When called, the scope is set to the data object and 119 * the name and value of the element are provided as arguments. 120 * @see jala.Form.Component.Input#setValue 121 * @type Function 122 */ 123 this.setter; // for doc purposes only 124 125 // that's where the value really is stored: 126 var setter = jala.Form.propertySetter; 127 128 this.__defineGetter__("setter", function() { return setter; }); 129 this.__defineSetter__("setter", function(newSetter) { 130 if (newSetter instanceof Function) { 131 setter = newSetter; 132 } 133 }); 134 92 135 var tracker = undefined; 93 136 … … 275 318 if (config.errorMessage) { 276 319 form.setErrorMessage(config.errorMessage); 320 } 321 if (config.getter) { 322 form.getter = config.getter; 323 } 324 if (config.setter) { 325 form.setter = config.setter; 277 326 } 278 327 if (config.components) { … … 1052 1101 * function is called to retrieve the original value of the 1053 1102 * field. When called, the scope is set to the data object and 1054 * the name of the element assole argument.1103 * the name of the element is the sole argument. 1055 1104 * @see #getValue 1056 1105 * @type Function … … 1175 1224 // handling re-rendering 1176 1225 return null; 1177 } else if (this.getter) {1178 return this.getter.call(this.form.getDataObject(), this.name);1179 1226 } else { 1180 return this.form.getDataObject()[this.name]; 1227 var getter = (this.getter) ? this.getter : this.form.getter; 1228 return getter.call(this.form.getDataObject(), this.name); 1181 1229 } 1182 1230 }; … … 1197 1245 */ 1198 1246 jala.Form.Component.Input.prototype.setValue = function(destObj, value) { 1199 // default value for th esetter is undefined, so if it has been1247 // default value for this.setter is undefined, so if it has been 1200 1248 // set to explicitly null, we don't save the value. in this case, 1201 1249 // we assume, the property is handled outside of jala.Form or purposely 1202 1250 // ignored at all. 1203 1251 if (this.setter !== null) { 1204 if (this.setter) { 1205 this.setter.call(destObj, this.name, value); 1206 } else { 1207 destObj[this.name] = value; 1208 } 1252 var setter = (this.setter) ? this.setter : this.form.setter; 1253 setter.call(destObj, this.name, value); 1209 1254 } 1210 1255 return; … … 1657 1702 if (reqData) { 1658 1703 attr.value = reqData[this.name]; 1659 } else if (value ) {1704 } else if (value instanceof Date) { 1660 1705 attr.value = this.getDateFormat().format(value); 1661 1706 } … … 2043 2088 }; 2044 2089 2045 /**2046 * Overrides Component.Input#setValue. For file uploads, there is no2047 * default property saving. A file upload can either be handled using2048 * a setter method or saved from outside the save method.2049 * @param {Object} destObj (optional) object whose values will be changed.2050 * @param {Object} value The value to set the property to2051 * @returns True in case the update was successful, false otherwise.2052 * @see jala.Form#setter2053 */2054 jala.Form.Component.File.prototype.setValue = function(destObj, value) {2055 if (this.setter) {2056 this.setter.call(destObj, this.name, value);2057 }2058 return;2059 };2060 2061 2062 2063 2064 2065 2090 2066 2091 /** … … 2129 2154 2130 2155 2131 2132 2156 /** 2157 * static default getter function used to return a field 2158 * from the data object. 2159 * @param {String} name Name of the property. 2160 * @type Object 2161 */ 2162 jala.Form.propertyGetter = function(name, value) { 2163 return this[name]; 2164 }; 2165 2166 /** 2167 * static default setter function used to change a field 2168 * of the data object. 2169 * @param {String} name Name of the property. 2170 * @param {Object} value New value of the property. 2171 */ 2172 jala.Form.propertySetter = function(name, value) { 2173 this[name] = value; 2174 }; 2133 2175 2134 2176
![(please configure the [header_logo] section in trac.ini)](/jala/chrome/common/trac_banner.png)