PDA

View Full Version : serializeForm not getting new values (1.1-Beta1)


ethraza
06-13-2007, 08:23 PM
Hi!
I'm using EXTjs 1.1-Beta1 with ext-base.js and ext-all.js.

I'm updating my code to use EXT only things over Prototype.js things, so I'm now changing the Form.serialize() functions for Ext.Ajax.serializeForm().

What is happenig is...

on mypage.html:
<html>
(...)
<input type="hidden" id="myinfo" name="myinfo">
(...)
</html>

<script type="text/javascript">
Ext.get('myinfo').value="Hi folks!";
Ext.Ajax.request(
{
url:'mypage.php',
params: 'Ext.Ajax.serializeForm('myform')',
method:'post',
callback: function(opts,suss,resp){getResponse(opts,suss,resp)}
}
);
</script>on page.php:
<?
echo $_POST['myinfo']; ==>> ''
?> So, why is serializeForm not getting the new value ('Hi folks!') assigned to myinfo as Form.serialize from Prototype did?

Is it a Bug from serializeForm or I'm missing something?


Thanks!

tryanDLS
06-13-2007, 11:03 PM
You didn't post any code with a form element so it's hard to say what's wrong. Set a BP in serializeForm and see what it's doing. Is it even finding your form?

ethraza
06-14-2007, 11:19 AM
There is a hidden form input as example, the rest of the form is complete normal. Ext.Ajax.serializeForm is getting all the value that come with input but is not getting the new values assigned to that inputs.
But I think that I discovered what is happenning, but don't know why.

I'm using Ext.get to get the forn input and change his value, but it seens to change only the value in the Javascript space, leting the HTML space as is.

When use Prototype, I did a $('myinfo').value="newinfo" with EXT I did Ext.get('myinfo').value="newinfo".

With $ from Prototype it changes the value of the input Element 'myinfo', but with Ext.get it change only in Javascript space, don't changing the input it self and if the serializeForm is getting the HTML information it is not seeing the new informations changed in Javascript space.

Ex.
After to do a Ext.get('myinfo').value="newinfo" on the <input type="text" id="myinfo" name="myinfo" value="oldinfo">

If
alert(Ext.get('myinfo').value); ==> 'newinfo'

and if
alert(Ext.get('myinfo').getValue()); ==> 'oldinfo'


So what I see is that serializeForm is getting the HTML space information as getValue() do.
In the docs of Ext.get it talks about a cache that is used, but I don't understand for what it is used.
I think that if I use a getElementById instead of Ext.get my example will work. If so, for what serves the Ext.get?

tryanDLS
06-14-2007, 12:21 PM
Element.value is not a property of an Element object, so by virtue of assigning it, you've created a new property on the object. You have not set the underlying DOM value property by doing this.

getValue() correctly returns the underlying dom.value which has not changed. If you want to set the value, you could do Ext.get('myfield').dom.value = 'foo', which will be correctly returned by getValue(). However, in this case you should consider using the Field objects rather than directly setting dom values.

The prototype $ function is just a shortcut to document.getElementById, it's not a returning a Element object wrapped around the dom object like Ext.get().

ethraza
06-14-2007, 12:43 PM
Oh, thanks for this explanation. This forum is really great, tell us the things that is not on documentation or is not so clear.
So it is not a bug. Is a missunderstand around Ext.get.

Only one thing to remain to all newbies...

However, in this case you should consider using the Field objects rather than directly setting dom values.
:-/
Ext.get('some_element').dom.value="foo" is not the right way to assign a new value?

tryanDLS
06-14-2007, 01:12 PM
However, in this case you should consider using the Field objects rather than directly setting dom values.
:-/
Ext.get('some_element').dom.value="foo" is not the right way to assign a new value?
You can do it that way if you're not using Ext.Forms and Fields. If you are, the preferred way would be to use the methods defined in the relevant objects.

mystix
06-15-2007, 10:59 AM
for any Ext widget which subclasses Ext.Component, setting an id in the widget's config will allow you to retrieve it via the Ext.ComponentMgr like sovar myWidget = Ext.ComponentMgr.get('my_widget_id');after which the setValue() method may be used to set both the display and underlying value at one go.