[Seaside] Best way to guarantee a textInput will be a positive integer?

Robert Sirois watchlala at hotmail.com
Tue Oct 26 20:46:21 UTC 2010


Wow that should go in the Seaside book Johan ;)

I also found, just on similar note here, that the clientside javascript is nice just to avoid unnecessary page reloads as Johan alluded to.

RS

Date: Tue, 26 Oct 2010 21:18:42 +0200
Subject: Re: [Seaside] Best way to guarantee a textInput will be a positive	integer?
From: gschtick at gmail.com
To: seaside at lists.squeakfoundation.org

Thanks that was exactly what I was looking for!

On Tue, Oct 26, 2010 at 9:07 PM, Johan Brichau <johan at inceptive.be> wrote:

Gilles,



If you want to verify the input at the server-side when the form is submitted, here's roughly what it would look like (writing this off the top of my head):



html form:[

        html textInput

                callback:[:val | [theInteger := val asInteger] on: Error do:[:e | anError := <do whatever you want> ]];

                with: '';

        html submitButton;

        ]



Essentially, you must catch the error inside the callback itself (or inside a method called from within the callback). When the callback is evaluated, the render method in which the callback is statically located is not on the execution stack.




When Seaside has finished executing the callback, it will (automatically) restart the render loop for your application. At that point, you can decide to render the error message, display the form again, or anything else you want to do.




Now, the example above uses traditional form submission. You might also want to do client-side verification using javascript, essentially not allowing to enter non-numeric characters in the input form, which is a completely different story. In addition, you might want to use ajax to submit the form and dynamically load an error message on the page.




Also, in Pharo pre 1.2 and (presumably) in Squeak, this conversion will not throw an error if 'val' is not an integer. Instead, it will return nil. So, the actual code in the callback might differ depending on the platform you are using.




I hope this answers your question



Johan



On 26 Oct 2010, at 17:00, Gilles Schtickzelle wrote:



> Hello again,

>

> I have a form where some of the input field should only be filled with integer values. I try to test the value in the setter and throw an error when it's not an integer but I can't figure out how to catch the error in the renderContentOn method of my component, and something tells me it's not the correct way to do this.


> Is there something like "integerInput" that would force an integer value instead of a textInput?

>

> Thanks,

> Gilles _______________________________________________

> seaside mailing list

> seaside at lists.squeakfoundation.org

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



_______________________________________________

seaside mailing list

seaside at lists.squeakfoundation.org

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




_______________________________________________
seaside mailing list
seaside at lists.squeakfoundation.org
http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside 		 	   		  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20101026/73c410f1/attachment-0001.htm


More information about the seaside mailing list