PDA

View Full Version : Suppressing empty text value of fields with .getValues() method?



jt1088
8 Nov 2010, 12:48 PM
I have search form tied to a grid.

I'm doing this to load the data:

store.load({
params:
Ext.getCmp('patientSearchForm').getForm().getValues()
});

Which is working well. Problem is for the form fields where I have set the empty text property, the value of the empty text gets posted to the server.

I also tried - Ext.getCmp('patientSearchForm').getForm().getFieldValues() - but this was not capturing all the form fields.

Is there a method I'm overlooking that will not send the emptyText values?

Foster
8 Nov 2010, 1:11 PM
For the combo box component I specified the "hiddenName" field which causes the valueField to be submitted.. there may be something similiar for the form fields you are using? But then again, on my combo boxes I also have allowBlank set to false so the user cannot submit without putting a value there anyway

jt1088
8 Nov 2010, 1:19 PM
Not really what I'm looking for....

Here's my field defs:


{
xtype: 'fieldset',
title: 'Name',
width: 270,
columnWidth: 0.4,
labelWidth: 35,
x: 10,
y: -8,
height: 60,
items: [
{
xtype: 'compositefield',
fieldLabel: 'Name',
anchor: '100%',
hideLabel: true,
layoutConfig: {

},
items: [
{
xtype: 'textfield',
flex: 1,
name: 'lastName',
selectOnFocus: true,
emptyText: 'Last Name',
maxLength: 50
},
{
xtype: 'textfield',
flex: 1,
maxLength: 50,
margins: '0 5 0 0',
name: 'firstName',
emptyText: 'First Name'
}
]
}
]
}

Ideally on the server side, I just want to test for a value. If not null, add the field to the search. I'm trying to avoid having to filter out the empty text string values on the server.

Foster
9 Nov 2010, 4:20 AM
I'm really not sure it's possible. Looking at the API for textfield it says

"The default text to place into an empty field (defaults to null). Note: that this value will be submitted to the server if this field is enabled and configured with a name (http://dev.sencha.com/deploy/dev/docs/output/Ext.form.TextField.html#Ext.form.TextField-name)."

It may be possible to Extend the text field so that the value is not submitted to the server. Or possibly in your search button click to try and send null if the textfield value = textfield emptyText

qooleot
7 Dec 2010, 4:53 PM
Quick hack:


var formValues = myForm.getForm().getValues();
for (prop in formValues) {
if (formValues[prop].replace('+',' ') ==
myForm.find('name', prop)[0].emptyText.replace('+',' ')) {
formValues[prop] = '';
}
};
console.log(formValues);

jt1088
8 Dec 2010, 3:48 PM
Cool man - thanks, gonna have to give it a try!