Scriptaculous example of SUEvaluator ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Scriptaculous example of SUEvaluator ?

Florian Minjat
Hi,
   I am trying to do a form with validators and confirmation in ajax.
All the validation need to be done server-side. My problem is to do
something like this in a onClick statement :
      isFormValid ifTrue: [html updater id: 'formDivId'; callback: [:r
| self renderValidFormOn: r]
   But I need to evaluate isFormValid server-side with an Ajax request
because it will only be set as true when the form is validate by ajax.
So currently this updater never shows up.
   I think I could use the SUEvaluator, but couldn't find any example.
So I don't really know how to use it.
   Does somebody know how to do that using as much seaside as
possible? And can somebody give me an example of SUEvaluator?

Florian
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Scriptaculous example of SUEvaluator ?

cbeler
Florian Minjat a écrit :

> Hi,
>   I am trying to do a form with validators and confirmation in ajax.
> All the validation need to be done server-side. My problem is to do
> something like this in a onClick statement :
>      isFormValid ifTrue: [html updater id: 'formDivId'; callback: [:r
> | self renderValidFormOn: r]
>   But I need to evaluate isFormValid server-side with an Ajax request
> because it will only be set as true when the form is validate by ajax.
> So currently this updater never shows up.
>   I think I could use the SUEvaluator, but couldn't find any example.
> So I don't really know how to use it.
>   Does somebody know how to do that using as much seaside as possible?
> And can somebody give me an example of SUEvaluator?
you have an example in the scriptaculous demo... CSS highlight in the
ajax tab...
SUEvaluator is like an updater except it injects a javascript chunk in
the pasge if I remember well...

your problem is because isFormValid is always set to false ?

maybe after each form input, you need to make a SURequest so as to
change this...

hth

cédrick
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Scriptaculous example of SUEvaluator ?

Florian Minjat
Cédrick ENIT wrote:

> Florian Minjat a écrit :
>> Hi,
>>   I am trying to do a form with validators and confirmation in ajax.
>> All the validation need to be done server-side. My problem is to do
>> something like this in a onClick statement :
>>      isFormValid ifTrue: [html updater id: 'formDivId'; callback: [:r
>> | self renderValidFormOn: r]
>>   But I need to evaluate isFormValid server-side with an Ajax request
>> because it will only be set as true when the form is validate by ajax.
>> So currently this updater never shows up.
>>   I think I could use the SUEvaluator, but couldn't find any example.
>> So I don't really know how to use it.
>>   Does somebody know how to do that using as much seaside as possible?
>> And can somebody give me an example of SUEvaluator?
> you have an example in the scriptaculous demo... CSS highlight in the
> ajax tab...
> SUEvaluator is like an updater except it injects a javascript chunk in
> the pasge if I remember well...
>
> your problem is because isFormValid is always set to false ?
>
> maybe after each form input, you need to make a SURequest so as to
> change this...
>
> hth
>
> cédrick

My problem is that isFormValid must be processed server-side. I could
add an hidden input for each validator and check it at the end but
this is pretty heavy, not very secure, and I still need to add a test
in javascript before the updater. I would rather prefer to use an Ajax
request to get the value to test.

I looked at the example in the demo. SUEvaluator could be the trick to
change the value of an hidden input.

But isn't there a simple way to do something like this :
onClick: ('if (', html ajaxRequest callback: [^ self isFormValid]
,')', html updater... )

Florian
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

SUCondition problem

Florian Minjat
Hi again,

I just played a little with the SUCondition which is clearly the key
to my problem (sorry I didn't saw it before). I have a problem though.
If I use an evaluator as the condition, the result is returned in
javascript as a string. The immediate problem is that a string as
condition in javascript always equals true.
The following code always shows an alert :
html scriptaculous script alert: 'test !'; condition: (html evaluator
callback: [:s | false])

I tried to add an '== ''false''' in several ways inside the condition,
but I can't manage to get something to work.

So I add a new SUStatement named SUEquals with this method :
printContentOn: aStream
        super printContentOn: aStream.
        aStream nextPut: $=; nextPut: $=; javascript: self statement

So now this script doesn't show an alert :
html scriptaculous script alert: 'test !'; condition: ((html evaluator
callback: [:s | false]) equals: 'false')

Was this possible without the creation of the SUEquals class ?

Florian


Florian Minjat wrote:

> Cédrick ENIT wrote:
>> Florian Minjat a écrit :
>>> Hi,
>>>   I am trying to do a form with validators and confirmation in ajax.
>>> All the validation need to be done server-side. My problem is to do
>>> something like this in a onClick statement :
>>>      isFormValid ifTrue: [html updater id: 'formDivId'; callback: [:r
>>> | self renderValidFormOn: r]
>>>   But I need to evaluate isFormValid server-side with an Ajax request
>>> because it will only be set as true when the form is validate by
>>> ajax. So currently this updater never shows up.
>>>   I think I could use the SUEvaluator, but couldn't find any example.
>>> So I don't really know how to use it.
>>>   Does somebody know how to do that using as much seaside as
>>> possible? And can somebody give me an example of SUEvaluator?
>> you have an example in the scriptaculous demo... CSS highlight in the
>> ajax tab...
>> SUEvaluator is like an updater except it injects a javascript chunk in
>> the pasge if I remember well...
>>
>> your problem is because isFormValid is always set to false ?
>>
>> maybe after each form input, you need to make a SURequest so as to
>> change this...
>>
>> hth
>>
>> cédrick
>
> My problem is that isFormValid must be processed server-side. I could
> add an hidden input for each validator and check it at the end but this
> is pretty heavy, not very secure, and I still need to add a test in
> javascript before the updater. I would rather prefer to use an Ajax
> request to get the value to test.
>
> I looked at the example in the demo. SUEvaluator could be the trick to
> change the value of an hidden input.
>
> But isn't there a simple way to do something like this :
> onClick: ('if (', html ajaxRequest callback: [^ self isFormValid] ,')',
> html updater... )
>
> Florian
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: SUCondition problem

Lukas Renggli
> The following code always shows an alert :
> html scriptaculous script alert: 'test !'; condition: (html evaluator
> callback: [:s | false])

The explanation: The A in AJAX stands for asynchronous. This means the
evaluator will send out the request and immediately return to the
caller without waiting for the response. So your expression

    html evaluator callback: [:s | false]

just returns the evaluator, not the result. In JavaScript anything but
false, null and undefined is true, therefor your alert gets triggered
all the time. The callback will be evaluated later on, but there is
nobody around for the result anymore.

A possible solution: You check the condition on the server and
generate the script from there:

    html evaluator callback: [ :script |
        self isSatisfied
           ifTrue: [ script alert: 'everything ok' ]
           ifFalse: [ script alert: 'ouch, there is something wrong' ] ]


Hope this helps,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside