Skip to content
Browse files

AutoEditableGrid : fix IE compatibility problem when json has a 'dele…

…te' key. WTF

forms: fix some date/time problems
  • Loading branch information...
1 parent 9381bbb commit b7545b52954f363ae57085b619df982723944949 @revolunet committed Mar 3, 2010
Showing with 20 additions and 5 deletions.
  1. +17 −3 forms.py
  2. +3 −2 static/js/Ext.ux.AutoEditableGrid.js
View
20 forms.py
@@ -10,14 +10,17 @@
def DateField_ExtJs_clean(value):
+ if value == '': return None
value = value.split('T')[0]
return value
def DateTimeField_ExtJs_clean(value):
+ if value == '': return None
value = value.replace('T', ' ')
return value
def TimeField_ExtJs_clean(value):
+ if value == '': return None
#value = value.split('T')[1]
return value
@@ -84,18 +87,29 @@ def getFieldConfig(field_name, django_field, value = None):
config['name'] = field_name
# foreignkeys or custom choices
- elif field_class_name in ['ModelChoiceField', 'TypedChoiceField'] or getattr(ofield, 'choices', None):
+ elif field_class_name in ['ForeignKey', 'ModelChoiceField', 'TypedChoiceField'] or getattr(ofield, 'choices', None):
config['xtype'] = 'combo'
config['blankText'] = field_name + ' :'
- choices= [[c[0], c[1]] for c in ofield.choices]
+ # removes the standard '-----'
+ form_field.empty_label = None
+ choices = form_field.choices
+ #print field_class_name, form_field.choices
+ #for i in form_field.choices:
+ # print i
+ choices = [[c[0], c[1]] for c in choices]
+ # if field_class_name == 'ForeignKey' and not getattr(ofield, 'choices', None):
+ # choices = [[c[0], c[1]] for c in ]
+
+
config['store'] = "new Ext.data.SimpleStore({fields: ['id','display'], data : %s })" % ( utils.JSONserialise(choices))
config['valueField'] = 'id'
config['displayField'] = 'display'
config['hiddenName'] = field_name
if field_class_name in ['ModelChoiceField', 'TypedChoiceField'] :
# disable foreignkeys edition
- config['editable'] = False
+ config['editable'] = True
config['forceSelection'] = True
+ config['typeAhead'] = True
config['mode'] = 'local'
config['triggerAction'] = 'all'
View
5 static/js/Ext.ux.AutoEditableGrid.js
@@ -56,6 +56,7 @@ Ext.ux.AutoEditableGrid = Ext.extend(Ext.ux.AutoGrid, {
// console.log(dels);
var sure = confirm("Sure to delete these "+ dels.length + " items ?");
+
if (dels.length > 0 ) {
Ext.Ajax.request({
url: this.store.proxy.url,
@@ -73,8 +74,8 @@ Ext.ux.AutoEditableGrid = Ext.extend(Ext.ux.AutoGrid, {
}
},
scope: this,
- params: { delete: dels.join(',')}
- });
+ params: { 'delete': dels.join(',')}
+ })
}
}
});

0 comments on commit b7545b5

Please sign in to comment.
Something went wrong with that request. Please try again.