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

Johan Brichau johan at inceptive.be
Tue Oct 26 19:07:13 UTC 2010


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



More information about the seaside mailing list