[Seaside] jQuery value.

Johan Brichau johan at inceptive.be
Thu Jul 5 17:54:57 UTC 2012


Malte,

I think you want this (explanation below):

|theValue|
(html textInput)
        id: id;
        onChange: ((html jQuery ajax serializeForm; onComplete: ((html jQuery id: 'imageDiv') load html: [:r | self renderImageOn: r]),((html jQuery ajax script:[:s | s << ((s jQuery id: id) value: (self formatValue: theValue))]));
	callback: [:val | theValue := val];
        value: (anObject perform: aValue)];

On a change event, you trigger the serialization of the form, which invokes the regular Seaside input field callback. This callback sets the value of the input field in a temporary variable. Afterwards (onComplete of the serialization of the form via ajax, the #imageDiv gets replaced and the value of the textfield replaced with it's formated value.  Mind that a blur of a textfield also triggers the change event (http://api.jquery.com/change/).

But this triggers 3 separate ajax calls. This can me improved:

|theValue|
(html textInput)
        id: id;
        onChange: ((html jQuery ajax serializeForm; onComplete: (html jQuery ajax script:[:s | s << ((s jQuery id: 'imageDiv') html: [:r | self renderImageOn: r])). s << ((s jQuery id: id) value: (self formatValue: theValue))]);
	callback: [:val | theValue := val];
        value: (anObject perform: aValue)];

Which has 2 ajax calls: one for the serialization of the form and one 'on completion' to make the replacements.
This can be improved further to a single ajax call:

|theValue|
(html textInput)
        id: id;
        onChange: (html jQuery ajax serializeForm; script:[:s | s << ((s jQuery id: 'imageDiv') html: [:r | self renderImageOn: r])). s << ((s jQuery id: id) value: (self formatValue: theValue))]);
	callback: [:val | theValue := val];
        value: (anObject perform: aValue)];

This works because the form serialization is a 'secondary callback' and will be executed first, followed by the ajax script callback, which produces the real answer to the ajax call.

Hope this helps
Johan


On 05 Jul 2012, at 15:28, Malte Grunwald wrote:

> Hey everybody,
> 
> i try to get the value of a textInput with jQuery by using  it this way:
> 
> (html textInput)
>                     id: id;
>                     onBlur: html jQuery ajax serializeForm;
>                     onBlur: ((html jQuery id: 'imageDiv') load html: [:r | self renderImageOn: r]);
>                     onChange: (html jQuery new load html: [self formatValue: (html jQuery id: id)value]);
>                     callback: [...];
>                     value: (anObject perform: aValue)];
> 
> but I do not get the real value in the formatValue: method. All I get is: JQueryInstance ($("#id4").val()).
> Have anybody an idea what I am doing wrong?
> 
> Thank you and kind regards 
> 
> Malte
> _______________________________________________
> seaside mailing list
> seaside at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside



More information about the seaside mailing list