[Commits] r2843 - in core/trunk/geoext: lib/GeoExt/plugins lib/GeoExt/widgets tests/lib/GeoExt/widgets
commits at geoext.org
commits at geoext.org
Mon Oct 3 15:49:43 CEST 2011
Author: elemoine
Date: 2011-10-03 15:49:43 +0200 (Mon, 03 Oct 2011)
New Revision: 2843
Modified:
core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js
core/trunk/geoext/lib/GeoExt/widgets/form.js
core/trunk/geoext/tests/lib/GeoExt/widgets/form.html
Log:
GeoExt.form.recordToField creates checkboxes with a boxLabel instead of a fieldLabel, p=fvanderbiest, r=me (closes #438)
Modified: core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js 2011-10-03 08:55:23 UTC (rev 2842)
+++ core/trunk/geoext/lib/GeoExt/plugins/AttributeForm.js 2011-10-03 13:49:43 UTC (rev 2843)
@@ -135,7 +135,9 @@
*/
fillForm: function() {
this.attributeStore.each(function(record) {
- var field = GeoExt.form.recordToField(record);
+ var field = GeoExt.form.recordToField(record, {
+ checkboxLabelProperty: 'fieldLabel'
+ });
if(field) {
this.formPanel.add(field);
}
Modified: core/trunk/geoext/lib/GeoExt/widgets/form.js
===================================================================
--- core/trunk/geoext/lib/GeoExt/widgets/form.js 2011-10-03 08:55:23 UTC (rev 2842)
+++ core/trunk/geoext/lib/GeoExt/widgets/form.js 2011-10-03 13:49:43 UTC (rev 2843)
@@ -92,6 +92,10 @@
/** private: function[recordToField]
* :param record: ``Ext.data.Record``, typically from an attributeStore
+ * :param options: ``Object``, optional object litteral. Valid options are:
+ * checkboxLabelProperty - ``String`` - The name of the property used to set
+ * the label in the checkbox. Only applies if the record is of the "boolean"
+ * type. Possible values are "boxLabel" and "fieldLabel". Default is "boxLabel".
*
* :return: ``Object`` An object literal with a xtype property, use
* ``Ext.ComponentMgr.create`` (or ``Ext.create`` in Ext 3) to create
@@ -101,9 +105,11 @@
* an ``Ext.data.Record`` containing name, type, restriction and
* label fields.
*/
-GeoExt.form.recordToField = function(record) {
+GeoExt.form.recordToField = function(record, options) {
+
+ options = options || {};
+
var type = record.get("type");
-
if(typeof type === "object" && type.xtype) {
// we have an xtype'd object literal in the type
// field, just return it
@@ -111,7 +117,6 @@
}
var field;
-
var name = record.get("name");
var label = record.get("label");
var restriction = record.get("restriction") || {};
@@ -152,9 +157,10 @@
} else if(type.match(r["boolean"])) {
field = {
xtype: "checkbox",
- name: name,
- boxLabel: label
+ name: name
};
+ var labelProperty = options.checkboxLabelProperty || "boxLabel";
+ field[labelProperty] = label;
} else if(type.match(r["date"])) {
field = {
xtype: "datefield",
Modified: core/trunk/geoext/tests/lib/GeoExt/widgets/form.html
===================================================================
--- core/trunk/geoext/tests/lib/GeoExt/widgets/form.html 2011-10-03 08:55:23 UTC (rev 2842)
+++ core/trunk/geoext/tests/lib/GeoExt/widgets/form.html 2011-10-03 13:49:43 UTC (rev 2843)
@@ -210,7 +210,7 @@
}
function test_recordToField(t) {
- t.plan(17);
+ t.plan(19);
// set up
@@ -246,11 +246,17 @@
t.eq(field.maxValue, 10, "[num] field maxValue is correct");
t.eq(field.minValue, 5, "[num] field minValue is correct");
- field = GeoExt.form.recordToField(store.getAt(2));
+ field = GeoExt.form.recordToField(store.getAt(2), {checkboxLabelProperty: 'fieldLabel'});
field = Ext.ComponentMgr.create(field);
t.ok(field instanceof Ext.form.Checkbox, "[bool] field is a checkbox");
t.eq(field.name, "BOOLEAN", "[bool] field name is correct");
+ t.eq(field.fieldLabel, "BOOLEAN", "[bool] field has correct fieldLabel");
+ field = GeoExt.form.recordToField(store.getAt(2));
+ field = Ext.ComponentMgr.create(field);
+ t.ok(field.boxLabel === "BOOLEAN" && field.fieldLabel === undefined,
+ "[bool] field with no option has correct boxLabel and no fieldLabel");
+
field = GeoExt.form.recordToField(store.getAt(3));
field = Ext.ComponentMgr.create(field);
t.ok(field instanceof Ext.form.DateField, "[datetime] field is a checkbox");
More information about the Commits
mailing list