Validating inputs before calling callback using AJAX serialization

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

Validating inputs before calling callback using AJAX serialization

Esteban A. Maringolo
Hi all,

I'm trying to find a clean and "proper" way of dealing with the validation of user entered values in forms _before_ they hit the callback block.

And based on such validation result be able to respond one script or another.

Let's say I have something like

html textInput
  onChange: (html jQuery ajax serializeThis);
  script: (html jQuery script: [:s | "fancy things that modify the web UI" ];
  callback: [:value | self doSomethingWithValue: value]

The problems with that are:
a) I can't "sanitize" the input before it reaches the callback block, I have to do it within the callback block.
b) I have no way to return one script for a successful validation, and one for a failing one.

I'd like something like

A)
html textInput
  onChange: (html jQuery ajax 
    serializeThisValidating: validationBlock
    successScript:  [:s | "fancy things that modify the web UI" ]
    failureScript:  [:s | "modify the web UI reporting the failure" ]);
  callback: [:value | self doSomethingWithValue: value]

or...
B)
html textInput
  onChange: (html jQuery ajax serializeThis);
  callback: [:value | self doSomethingWithValue: value ]
  validation: aBlock
  successScript: [:s | "fancy things that modify the web UI" ]
  failureScript:   [:s | "modify the web UI reporting the failure" ].


I think that the A option is the best alternative, since all the "special handling" will happen in the context of the JQAjax and maybe a special kind of JSAjaxCallback). 

Also I don't know how this would work in the context of _several_ validated callbacks, but I plan to make it work in the context of #serializeThis only.

But I'm sure there is a simpler way of achieving this, since I tend to make things complicated.

Any suggestions?


Esteban A. Maringolo

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

Re: Validating inputs before calling callback using AJAX serialization

Paul DeBruicker
In your Seaside callback: could you do a

html anchor
    callback:[:val | self validateWith: [:v | self validateOutsideInput: v]
thenExecute: [:v | self myOriginalCallbackMethods: v] for: val]


and

validateWith: validationBlock thenExecute: callbackBlock for: submittedValue
   (validationBlock cull: submittedValue) ifTrue:[callbackBlock cull:
submittedValue]


?

I don't really understand what happens when callbacks are executed from the
seaside perspective that would want you to keep it from executing.  The pile
of stuff I don't understand grows daily though :)

Hope this helps


Paul




Esteban A. Maringolo wrote

> Hi all,
>
> I'm trying to find a clean and "proper" way of dealing with the validation
> of user entered values in forms _before_ they hit the callback block.
>
> And based on such validation result be able to respond one script or
> another.
>
> Let's say I have something like
>
> html textInput
>   onChange: (html jQuery ajax serializeThis);
>   script: (html jQuery script: [:s | "fancy things that modify the web UI"
> ];
>   callback: [:value | self doSomethingWithValue: value]
>
> The problems with that are:
> a) I can't "sanitize" the input before it reaches the callback block, I
> have to do it within the callback block.
> b) I have no way to return one script for a successful validation, and one
> for a failing one.
>
> I'd like something like
>
> A)
> html textInput
>   onChange: (html jQuery ajax
>     serializeThisValidating: validationBlock
>     successScript:  [:s | "fancy things that modify the web UI" ]
>     failureScript:  [:s | "modify the web UI reporting the failure" ]);
>   callback: [:value | self doSomethingWithValue: value]
>
> or...
> B)
> html textInput
>   onChange: (html jQuery ajax serializeThis);
>   callback: [:value | self doSomethingWithValue: value ]
>   validation: aBlock
>   successScript: [:s | "fancy things that modify the web UI" ]
>   failureScript:   [:s | "modify the web UI reporting the failure" ].
>
>
> I think that the A option is the best alternative, since all the "special
> handling" will happen in the context of the JQAjax and maybe a special
> kind
> of JSAjaxCallback).
>
> Also I don't know how this would work in the context of _several_
> validated
> callbacks, but I plan to make it work in the context of #serializeThis
> only.
>
> But I'm sure there is a simpler way of achieving this, since I tend to
> make
> things complicated.
>
> Any suggestions?
>
>
> Esteban A. Maringolo
>
> _______________________________________________
> seaside mailing list

> seaside@.squeakfoundation

> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside





--
Sent from: http://forum.world.st/Seaside-General-f86180.html
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
Reply | Threaded
Open this post in threaded view
|

Re: Validating inputs before calling callback using AJAX serialization

Esteban A. Maringolo
Hi Paul,

It is not the validation of the data per-se what I'd need, but a
different AJAX response whether the validation succeeded.

Validating the data before it hits the model can be done within the
callback itself, as in your example.
But the callback execution is separated from the response of the AJAX
callback (JQAjaxCallback).
I toyed around with a particular subclass of JQAjaxCallback, but then
I made a pause because I might be killing a mosquito with a shotgun
(again). Didn't come back to it since then.

Regards!


Esteban A. Maringolo


2018-01-18 16:09 GMT-03:00 Paul DeBruicker <[hidden email]>:

> In your Seaside callback: could you do a
>
> html anchor
>     callback:[:val | self validateWith: [:v | self validateOutsideInput: v]
> thenExecute: [:v | self myOriginalCallbackMethods: v] for: val]
>
>
> and
>
> validateWith: validationBlock thenExecute: callbackBlock for: submittedValue
>    (validationBlock cull: submittedValue) ifTrue:[callbackBlock cull:
> submittedValue]
>
>
> ?
>
> I don't really understand what happens when callbacks are executed from the
> seaside perspective that would want you to keep it from executing.  The pile
> of stuff I don't understand grows daily though :)
>
> Hope this helps
>
>
> Paul
>
>
>
>
> Esteban A. Maringolo wrote
>> Hi all,
>>
>> I'm trying to find a clean and "proper" way of dealing with the validation
>> of user entered values in forms _before_ they hit the callback block.
>>
>> And based on such validation result be able to respond one script or
>> another.
>>
>> Let's say I have something like
>>
>> html textInput
>>   onChange: (html jQuery ajax serializeThis);
>>   script: (html jQuery script: [:s | "fancy things that modify the web UI"
>> ];
>>   callback: [:value | self doSomethingWithValue: value]
>>
>> The problems with that are:
>> a) I can't "sanitize" the input before it reaches the callback block, I
>> have to do it within the callback block.
>> b) I have no way to return one script for a successful validation, and one
>> for a failing one.
>>
>> I'd like something like
>>
>> A)
>> html textInput
>>   onChange: (html jQuery ajax
>>     serializeThisValidating: validationBlock
>>     successScript:  [:s | "fancy things that modify the web UI" ]
>>     failureScript:  [:s | "modify the web UI reporting the failure" ]);
>>   callback: [:value | self doSomethingWithValue: value]
>>
>> or...
>> B)
>> html textInput
>>   onChange: (html jQuery ajax serializeThis);
>>   callback: [:value | self doSomethingWithValue: value ]
>>   validation: aBlock
>>   successScript: [:s | "fancy things that modify the web UI" ]
>>   failureScript:   [:s | "modify the web UI reporting the failure" ].
>>
>>
>> I think that the A option is the best alternative, since all the "special
>> handling" will happen in the context of the JQAjax and maybe a special
>> kind
>> of JSAjaxCallback).
>>
>> Also I don't know how this would work in the context of _several_
>> validated
>> callbacks, but I plan to make it work in the context of #serializeThis
>> only.
>>
>> But I'm sure there is a simpler way of achieving this, since I tend to
>> make
>> things complicated.
>>
>> Any suggestions?
>>
>>
>> Esteban A. Maringolo
>>
>> _______________________________________________
>> seaside mailing list
>
>> seaside@.squeakfoundation
>
>> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
>
>
>
>
>
> --
> Sent from: http://forum.world.st/Seaside-General-f86180.html
> _______________________________________________
> seaside mailing list
> [hidden email]
> http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside
_______________________________________________
seaside mailing list
[hidden email]
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside