Changeset 231
- Timestamp:
- 05/10/07 15:55:13 (6 years ago)
- Location:
- jala/trunk
- Files:
-
- 2 modified
-
code/Form.js (modified) (26 diffs)
-
tests/Form.js (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
jala/trunk/code/Form.js
r230 r231 75 75 * @see #save 76 76 */ 77 this.setDataObj = function(newDataObj) {77 this.setDataObject = function(newDataObj) { 78 78 dataObj = newDataObj; 79 79 return; … … 85 85 * @returns The data object of this jala.Form instance 86 86 */ 87 this.getDataObj = function() {87 this.getDataObject = function() { 88 88 return dataObj; 89 89 }; … … 165 165 166 166 // init private fields: 167 var submitCaption, errorMessage = undefined; 168 169 /** 170 * Returns the caption of the submit button. 171 * @returns caption 167 var submitValue, errorMessage = undefined; 168 169 /** 170 * Returns the value (ie. text) of the submit button. 172 171 * @type String 173 172 */ 174 this.getSubmit Caption= function() {175 return submit Caption;173 this.getSubmitValue = function() { 174 return submitValue; 176 175 }; 177 176 178 177 /** 179 * Sets the captionof the submit button.180 * @param {String} new Caption181 */ 182 this.setSubmit Caption = function(newCaption) {183 submit Caption = newCaption;178 * Sets the value (ie. text) of the submit button. 179 * @param {String} newSubmitValue 180 */ 181 this.setSubmitValue = function(newSubmitValue) { 182 submitValue = newSubmitValue; 184 183 return; 185 184 }; … … 271 270 form.setLegend(config.legend); 272 271 } 273 if (config.submit Caption) {274 form.setSubmit Caption(config.submitCaption);272 if (config.submitValue) { 273 form.setSubmitValue(config.submitValue); 275 274 } 276 275 if (config.errorMessage) { … … 299 298 var constr = jala.Form.Component[clazzName]; 300 299 if (!constr) { 301 // invalid constructor 300 // invalid constructor: 302 301 var logStr = "jala.Form encountered unknown component type " + element["type"] + " in config of form "; 303 302 logStr += (container.form) ? container.form.name : container.name; … … 305 304 continue; 306 305 } 307 var component = new constr(element.name); 306 var name = element.name; 307 if (!name && element.label) { 308 name = element.label.toAlphanumeric().toLowerCase(); 309 } else if (!name && constr == jala.Form.Component.Fieldset) { 310 var str = "fieldset"; 311 while(container.components[str]) { 312 str += "1"; 313 } 314 name = str; 315 } else if (!name) { 316 // couldn't find a name for the component: 317 var logStr = "jala.Form encountered component of type " + clazzName.toLowerCase() + " without name or label property in config of form "; 318 logStr += (container.form) ? container.form.name : container.name; 319 app.log(logStr); 320 continue; 321 } 322 var component = new constr(name); 308 323 container.addComponent(component); // make sure that component.form is set before the loop! 309 324 for (var key in element) { … … 322 337 component[key] = element[key]; 323 338 break; 324 case jala.Form.REQUIRE D:339 case jala.Form.REQUIRE: 325 340 component.require(key, true, msg); 326 341 break; … … 405 420 name: this.createDomId("submit"), 406 421 "class": "submit", 407 "value": this.getSubmit Caption() || "Submit"}422 "value": this.getSubmitValue() || "Submit"} 408 423 ); 409 424 jala.Form.html.closeTag("div"); … … 475 490 * @param {Object} destObj (optional) object whose values will be changed. 476 491 * By default the dataObj passed to the constructor or to 477 * setDataObj is used.492 * setDataObject is used. 478 493 */ 479 494 jala.Form.prototype.save = function(tracker, destObj) { 480 495 tracker = (tracker) ? tracker : this.getTracker(); 481 destObj = (destObj) ? destObj : this.getDataObj ();496 destObj = (destObj) ? destObj : this.getDataObject(); 482 497 var components = this.listComponents(); 483 498 for (var i=0; i<components.length; i++) { … … 559 574 * Constant used by require function to define that a component 560 575 * should validate only if the user did provide input. 561 * Value: "require d"562 * @type String 563 */ 564 jala.Form.REQUIRE D = "required";576 * Value: "require" 577 * @type String 578 */ 579 jala.Form.REQUIRE = "require"; 565 580 566 581 /** … … 632 647 */ 633 648 jala.Form.Component = function Component(name) { 649 650 if (!name) { 651 throw "jala.Form.Component constructed without name."; 652 } 653 634 654 /** 635 655 * The Form this component belongs to … … 881 901 */ 882 902 jala.Form.Component.Skin.prototype.render = function() { 883 var obj = (this.getHandler()) ? this.getHandler() : this.form.getDataObj ();903 var obj = (this.getHandler()) ? this.getHandler() : this.form.getDataObject(); 884 904 obj.renderSkin(this.name, this); 885 905 return; … … 905 925 /** 906 926 * Sets a requirement for this component. 907 * If function is called without arguments, jala.Form.REQUIRE D927 * If function is called without arguments, jala.Form.REQUIRE 908 928 * is set to true. 909 929 * @param {String} key String defining the type of requirement, … … 916 936 if (arguments.length == 0) { 917 937 // set default value for arguments 918 key = jala.Form.REQUIRE D;938 key = jala.Form.REQUIRE; 919 939 val = true; 920 940 } … … 950 970 * Returns a specific message for a config element. 951 971 * @param {String} key The key of the message as defined by 952 * the constants in jala.Form.* (e.g. "require d",972 * the constants in jala.Form.* (e.g. "require", 953 973 * "maxlength", "minlength" ... 954 974 * @param {String} defaultMsg the message to use when no message … … 1112 1132 if (this.validator) { 1113 1133 error = this.validator.call( 1114 this.form.getDataObj (),1134 this.form.getDataObject(), 1115 1135 this.name, 1116 1136 tracker.values[this.name], … … 1156 1176 return null; 1157 1177 } else if (this.getter) { 1158 return this.getter.call(this.form.getDataObj (), this.name);1178 return this.getter.call(this.form.getDataObject(), this.name); 1159 1179 } else { 1160 return this.form.getDataObj ()[this.name];1180 return this.form.getDataObject()[this.name]; 1161 1181 } 1162 1182 }; … … 1197 1217 */ 1198 1218 jala.Form.Component.Input.prototype.render = function() { 1199 var className = (this.getRequirement(jala.Form.REQUIRE D) == true) ? "required" : "optional";1219 var className = (this.getRequirement(jala.Form.REQUIRE) == true) ? "require" : "optional"; 1200 1220 if (this.getClassName()) { 1201 1221 className += " " + this.getClassName(); … … 1350 1370 1351 1371 /** 1352 * Checks user input for maximum length, minimum length and require d1372 * Checks user input for maximum length, minimum length and require 1353 1373 * if the corresponding options have been set using the require method. 1354 1374 * @param {Object} reqData request data … … 1358 1378 */ 1359 1379 jala.Form.Component.Input.prototype.checkLength = function(reqData) { 1360 var require d = this.getRequirement(jala.Form.REQUIRED);1380 var require = this.getRequirement(jala.Form.REQUIRE); 1361 1381 var minLength = this.getRequirement(jala.Form.MINLENGTH); 1362 1382 var maxLength = this.getRequirement(jala.Form.MAXLENGTH); 1363 1383 1364 if (require d&& (reqData[this.name] == null || reqData[this.name].trim() == "")) {1365 return this.getMessage(jala.Form.REQUIRE D, "Please enter text into this field.");1384 if (require && (reqData[this.name] == null || reqData[this.name].trim() == "")) { 1385 return this.getMessage(jala.Form.REQUIRE, "Please enter text into this field."); 1366 1386 } else if (maxLength && reqData[this.name].length > maxLength) { 1367 1387 return this.getMessage(jala.Form.MAXLENGTH, "Input for this field is too long ({0} characters). Please enter no more than {1} characters.", … … 1371 1391 // but don't throw an error if the element is optional and empty 1372 1392 if (reqData[this.name].length < minLength && 1373 (require d || (!required&& reqData[this.name].length > 0))) {1393 (require || (!require && reqData[this.name].length > 0))) { 1374 1394 return this.getMessage(jala.Form.MINLENGTH, "Input for this field is too short ({0} characters). Please enter at least {1} characters.", 1375 1395 reqData[this.name].length, minLength); … … 1774 1794 return options; 1775 1795 } else if (options instanceof Function) { 1776 return options.call(this.form.getDataObj (), this.name);1796 return options.call(this.form.getDataObject(), this.name); 1777 1797 } 1778 1798 } … … 1789 1809 jala.Form.Component.Select.prototype.checkOptions = function(reqData) { 1790 1810 // if field is required, an empty option is not allowed: 1791 var found = (!this.getRequirement(jala.Form.REQUIRE D) && !reqData[this.name]);1811 var found = (!this.getRequirement(jala.Form.REQUIRE) && !reqData[this.name]); 1792 1812 if (!found) { 1793 1813 if (this.getRequirement(jala.Form.CHECKOPTIONS) === false) { … … 1986 2006 1987 2007 /** 1988 * Validates a file upload by making sure it's there (if REQUIRE Dis set),2008 * Validates a file upload by making sure it's there (if REQUIRE is set), 1989 2009 * checking the file size, the content type and by trying to construct an image. 1990 2010 * @param {Object} reqData request data … … 1997 2017 if (reqData[this.name].contentLength == 0) { 1998 2018 // no upload 1999 if (this.getRequirement(jala.Form.REQUIRE D) == true) {2000 return this.getMessage(jala.Form.REQUIRE D, "File upload is required.");2019 if (this.getRequirement(jala.Form.REQUIRE) == true) { 2020 return this.getMessage(jala.Form.REQUIRE, "File upload is required."); 2001 2021 } else { 2002 2022 // no further checks necessary, exit here … … 2050 2070 2051 2071 /** 2052 * Validates an image upload by making sure it's there (if REQUIRE Dis set),2072 * Validates an image upload by making sure it's there (if REQUIRE is set), 2053 2073 * checking the file size, the content type and by trying to construct an image. 2054 2074 * If the file is an image, width and height limitations set by require are -
jala/trunk/tests/Form.js
r230 r231 70 70 assertEqual(list[++idx].name, "div"); 71 71 assertAttribute(list[idx].attributes, "id", "test_alias_row"); 72 assertAttribute(list[idx].attributes, "class", "row require d");72 assertAttribute(list[idx].attributes, "class", "row require"); 73 73 74 74 assertEqual(list[++idx].name, "label"); … … 96 96 assertEqual(list[++idx].name, "div"); 97 97 assertAttribute(list[idx].attributes, "id", "test_desc_row"); 98 assertAttribute(list[idx].attributes, "class", "row require d");98 assertAttribute(list[idx].attributes, "class", "row require"); 99 99 100 100 assertEqual(list[++idx].name, "label"); … … 117 117 assertEqual(list[++idx].name, "div"); 118 118 assertAttribute(list[idx].attributes, "id", "test_pushdate_row"); 119 assertAttribute(list[idx].attributes, "class", "row require d");119 assertAttribute(list[idx].attributes, "class", "row require"); 120 120 121 121 assertEqual(list[++idx].name, "label"); … … 242 242 assertAttribute(list[idx].attributes, "class", "submit"); 243 243 assertAttribute(list[idx].attributes, "name", "test_submit"); 244 assertAttribute(list[idx].attributes, "value", "S ubmit");244 assertAttribute(list[idx].attributes, "value", "Save"); 245 245 assertAttribute(list[idx].attributes, "type", "submit"); 246 246 … … 308 308 */ 309 309 var testFormSave = function() { 310 var dataObj = form.getDataObj ();310 var dataObj = form.getDataObject(); 311 311 312 312 var reqData = getRequestData(); … … 400 400 return { 401 401 name: "test", 402 submit :"Save",402 submitValue: "Save", 403 403 components:[ 404 404 { … … 408 408 minlength: 4, 409 409 maxlength: 10, 410 require d:true,410 require: true, 411 411 messages: { 412 require d:"Alias is required.",412 require: "Alias is required.", 413 413 maxlength: "Alias is too long.", 414 414 minlength: "Alias is too short." … … 420 420 rows: 3, 421 421 cols: 30, 422 require d:true,422 require: true, 423 423 getter: function(name) { 424 424 return this.getProperty(name); … … 432 432 type: "date", 433 433 dateFormat: "d.M.yyyy H:m", 434 require d:true434 require: true 435 435 }, 436 436 {
![(please configure the [header_logo] section in trac.ini)](/jala/chrome/common/trac_banner.png)