PDA

View Full Version : DateField: displayFormat VS submitFormat



tobiu
9 Feb 2010, 10:16 AM
hi together,

while translating my app i realised that there is only one config for formats for Ext.form.DateField. I would like to let the displayFormat vary for each chosen language, but the format the date is send to the server shall stay the same.

is there already a way to configurate the behaviour that way or shall i start implementing it?

kind regards,
tobiu

sramanna
9 Feb 2010, 1:00 PM
I had the same question.. Anyone knows please.

tobiu
10 Feb 2010, 12:48 AM
ok, no need for doing it myself. i completely missed, saki already build a XDateField.
http://www.extjs.com/forum/showthread.php?t=25900

i am not sure, if the approach of vivid-planet -> modifying the submit-action is something i like better.

kind regards,
tobiu

tobiu
10 Feb 2010, 1:12 AM
i modified the code of vivid-planet a little bit and trying out:



bT.SubmitAction = function(form, options){
bT.SubmitAction.superclass.constructor.call(this, form, options);
};

Ext.extend(bT.SubmitAction, Ext.form.Action.Submit, {
run : function(){
if (!this.options.params) this.options.params = {};

this.form.items.each(function(field) {
if (field.disabled) {
this.options.params[field.getName()] = null;

} else if (field instanceof Ext.form.Checkbox) {
this.options.params[field.getName()] = field.getValue() ? 1 : 0;

} else if (field instanceof Ext.form.DateField) {
this.options.params[field.getName()] = field.getValue().dateFormat("Y-m-d");

} else if (field.rendered && field.el.dom.type == 'file') {
//skip, can't be read out through JS
return;
} /*else {
var v = field.getValue();
if (typeof v == 'object') {
v = Ext.encode(v);
}
this.options.params[field.getName()] = v;
}*/
if (field.rendered) {
field.realName = field.getName();
field.el.dom.name = '';
}
}, this);

bT.SubmitAction.superclass.run.call(this);

//restore names
this.form.items.each(function(field) {
if (field.realName) {
field.el.dom.name = field.realName;
delete field.realName;
}
}, this);
}
});
Ext.form.Action.ACTION_TYPES.submit = bT.SubmitAction;


right now. bT is my comon namespace.

kind regards,
tobiu

Animal
10 Feb 2010, 1:25 AM
I like the idea of actually submitting collected values rather than what is in the DOM input fields.

I also think an event should be available to enable you to get in and examine/change the submit data:



bT.SubmitAction = function(form, options){
bT.SubmitAction.superclass.constructor.call(this, form, options);
};

Ext.extend(bT.SubmitAction, Ext.form.Action.Submit, {
run : function(){
if (!this.options.params) this.options.params = {};

this.form.items.each(function(field) {
if (field.disabled) {
this.options.params[field.getName()] = null;

} else if (field instanceof Ext.form.Checkbox) {
this.options.params[field.getName()] = field.getValue() ? 1 : 0;

} else if (field instanceof Ext.form.DateField) {
this.options.params[field.getName()] = field.getValue().dateFormat("Y-m-d");

} else if (field.rendered && field.el.dom.type == 'file') {
//skip, can't be read out through JS
return;
} /*else {
var v = field.getValue();
if (typeof v == 'object') {
v = Ext.encode(v);
}
this.options.params[field.getName()] = v;
}*/
if (field.rendered) {
field.realName = field.getName();
field.el.dom.name = '';
}
}, this);

// Allow developer to examine and modify parameters on BasicForm's "beforesubmit" event.
this.form.fireEvent("beforesubmit", this.options.params);

bT.SubmitAction.superclass.run.call(this);

//restore names
this.form.items.each(function(field) {
if (field.realName) {
field.el.dom.name = field.realName;
delete field.realName;
}
}, this);
}
});
Ext.form.Action.ACTION_TYPES.submit = bT.SubmitAction;

mystix
11 Feb 2010, 9:15 AM
@animal, remember the ux.OOSubmit plugin for Ext 2.x?
133661

last mention by @brian was that something like this was "in the works".
looks like it never made it to the codebase though. feature request perhaps?


[edit]
@nige, if i remember correctly, you also had a feature request up for this somewhere
-- iirc, you were requesting that the BasicForm collect its values via each child Field's getValue() method as opposed to grabbing it from the DOM.

tobiu
11 Feb 2010, 9:35 AM
@nige: i don't have a current use for the listener, but it definitely makes sense and could be useful.

@mystix: i think many users using forms could need this by default. at least every(!) user trying to set up an app with multiple languages. so +1 ;)


kind regards,
tobiu