PDA

View Full Version : Textfield + SetRawValue



parsbin
2 Jul 2011, 1:37 AM
Hi
can i use setRawValue for textfields?
what is problem of my code?




Ext.getCmp('sum').setValue("aaaaaaaa");
Ext.getCmp('sum').setRawValue("ssssssss");

alert(Ext.getCmp('sum').getRawValue()); //returned sssssss
alert(Ext.getCmp('sum').getValue()); //returned sssssss but i want return aaaaa

parsbin
2 Jul 2011, 9:08 PM
not idea?

aramaki
3 Jul 2011, 9:28 AM
getRawData: Returns the raw data value which may or may not be a valid, defined value
getVAlue: Returns the normalized data value (undefined or emptyText will be returned as '')

in your case, the results a similar because (as I guess) you dont specify any validation rules. try to investigate sources of both functions to clear

parsbin
3 Jul 2011, 11:57 PM
can you explain better?

skirtle
5 Jul 2011, 1:25 PM
Why are you trying to make the value and raw value different? They are effectively just two different ways of accessing the same value: the value of the underlying HTML input element.

For a textfield the differences are really just how it handles invalid values. For other fields, like numberfield, the raw value is a string whereas the value is a number.

Unless you have a good reason not to you should just use setValue() and getValue() and avoid raw value altogether.

parsbin
6 Jul 2011, 1:16 AM
so
i want receive a number similar to Money format (123,456,789) .
but i want get orginal value for save to databse (123456789)

how can i do that?

parsbin
7 Jul 2011, 12:00 AM
not any adea?
i want type into textfield same to money format
123,456,789

how ?

pavanextjs
7 Jul 2011, 10:43 AM
var val = urTextField.getValue();
var numVal = val.replace(/,/g, '');

parsbin
8 Jul 2011, 9:12 PM
very thanks.
next question:
i want split my numbers in money format in input textfield.
how can do this?

http://033.img98.net/out.php/i462067_numberssplit.png

skirtle
10 Jul 2011, 5:00 PM
Something like this maybe?


new Ext.form.TextField({
maskRe: /\d|,/,
renderTo: Ext.getBody(),
listeners: {
change: function(field, value) {
var strippedValue = Number(value.replace(/\D/g, '')) || 0;
var newValue = Ext.util.Format.number(strippedValue, '0,000');

if (newValue !== value) {
field.setValue(newValue);
}
}
}
});

You need to be very careful doing manipulation with monetary values. Problems such as rounding errors can occur trying to do 'clever' things like this.