Learning Web Development with Seaside 3.0

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

Learning Web Development with Seaside 3.0

Michel Duf
Hi

Is there a easy way to add field validation in the form example provided in the Gemstone seaside tutorial?

Thanks
Michel
Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

James Foster-8
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

        canvas textInput
                onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.

Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

Paul DeBruicker
On the client the jQuery Validate plugin is pretty handy:

http://docs.jquery.com/Plugins/Validation



On 10/03/2011 12:22 PM, James Foster wrote:

> Hi Michael,
>
> Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:
>
> canvas textInput
> onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';
>
> Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.
>
> James
>
> On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:
>
>> Hi
>>
>> Is there a easy way to add field validation in the form example provided in
>> the Gemstone seaside tutorial?
>>
>> Thanks
>> Michel
>>
>> --
>> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
>> Sent from the GLASS mailing list archive at Nabble.com.
>

Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

Michel Duf
In reply to this post by James Foster-8
Hi

Here my problem from the Gemstone code

LBEventEditor>renderButtonsOn: html
html
div: [ 
html
span: [ 
html cancelButton
callback: [ self answer: false ];
with: 'Cancel' ].
html
span: [ 
html submitButton
callback: [ 
(model where = 'test' and: [ model who = 'staff' ])
ifTrue: [ 
self inform: 'Validation Errors! '.
self answer: false. ]
ifFalse: [ self save ] ];
with: 'Save' ] ]

When I edit a event with an error (eg: model where = 'test' and who = 'staff')
if I click SUBMIT I see my Validation Error! message but the model has been updated!!!

As expected when I click CANCEL the model is not updated.

Michel

On Mon, Oct 3, 2011 at 12:22 PM, James Foster <[hidden email]> wrote:
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

       canvas textInput
               onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique
Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

James Foster-8
Michael,

You say that the model has been updated. I wonder if the entire model was updated or only the portions of the model that are modified by callbacks, including #'what:' and #'where:'? Is the #'save' method called when you get a validation error? Are the #'when:' and #'gameType:' values updated if there is a validation error (these are updated in the #'save' method)?

I believe that the system recognizes a difference between the cancel button and the submit button and behaves differently with respect to the various callbacks. From the point of view of the system, it doesn't know that your submit callback (which runs after the other callbacks) decided that things were invalid. In fact, your submit button callback is explicitly checking the domain values #'where' and #'who', so you should be aware that those values have been updated.

The true/false value returned by #'answer:' is simply an object that is returned by the #'call:' message. It is not meaningful for purposes of applying callbacks (those have already run) or deciding whether the domain should be updated (it is too late). The true/false is simply a value that is used to tell the caller which #'inform:' message to send. The framework doesn't know what meaning you apply to those objects.

If you want to wait to apply new values to the domain model till you have determined that they are valid, then my earlier comment applies:

"To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated." 

That is, modify the callback so that instead of inserting the new value directly into the model, you put it in a new instance variable in the component. Your validation would then look at the instance variables in the component, not in the model. It would not be till the #'save' method that the new values would be copied from the component instance variables to the model.

Let us know if this makes sense. You are asking good questions and I think you are close to understanding how Seaside handles things. 

James


From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Tuesday, October 4, 2011 6:53:49 PM
Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0

Hi

Here my problem from the Gemstone code

LBEventEditor>renderButtonsOn: html
html
div: [ 
html
span: [ 
html cancelButton
callback: [ self answer: false ];
with: 'Cancel' ].
html
span: [ 
html submitButton
callback: [ 
(model where = 'test' and: [ model who = 'staff' ])
ifTrue: [ 
self inform: 'Validation Errors! '.
self answer: false. ]
ifFalse: [ self save ] ];
with: 'Save' ] ]

When I edit a event with an error (eg: model where = 'test' and who = 'staff')
if I click SUBMIT I see my Validation Error! message but the model has been updated!!!

As expected when I click CANCEL the model is not updated.

Michel

On Mon, Oct 3, 2011 at 12:22 PM, James Foster <[hidden email]> wrote:
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

       canvas textInput
               onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique

Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

Michel Duf
James,

Thanks a lot for the fast answer while I am considering using Seaside for my web development instead JAVA or Ruby :)

No the save method is not call when errors.

I think that I understand what you are just told me... I will try to make  capture new values temporaly in the component and update my model with thoses new values only if I got no errors.

What I do not understing, is when I click CANCEL the change is not applied... and the model should already been updated (as you said)...

Michel

On Wed, Oct 5, 2011 at 1:46 AM, James Foster <[hidden email]> wrote:
Michael,

You say that the model has been updated. I wonder if the entire model was updated or only the portions of the model that are modified by callbacks, including #'what:' and #'where:'? Is the #'save' method called when you get a validation error? Are the #'when:' and #'gameType:' values updated if there is a validation error (these are updated in the #'save' method)?

I believe that the system recognizes a difference between the cancel button and the submit button and behaves differently with respect to the various callbacks. From the point of view of the system, it doesn't know that your submit callback (which runs after the other callbacks) decided that things were invalid. In fact, your submit button callback is explicitly checking the domain values #'where' and #'who', so you should be aware that those values have been updated.

The true/false value returned by #'answer:' is simply an object that is returned by the #'call:' message. It is not meaningful for purposes of applying callbacks (those have already run) or deciding whether the domain should be updated (it is too late). The true/false is simply a value that is used to tell the caller which #'inform:' message to send. The framework doesn't know what meaning you apply to those objects.

If you want to wait to apply new values to the domain model till you have determined that they are valid, then my earlier comment applies:

"To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated." 

That is, modify the callback so that instead of inserting the new value directly into the model, you put it in a new instance variable in the component. Your validation would then look at the instance variables in the component, not in the model. It would not be till the #'save' method that the new values would be copied from the component instance variables to the model.

Let us know if this makes sense. You are asking good questions and I think you are close to understanding how Seaside handles things. 

James


From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Tuesday, October 4, 2011 6:53:49 PM
Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0


Hi

Here my problem from the Gemstone code

LBEventEditor>renderButtonsOn: html
html
div: [ 
html
span: [ 
html cancelButton
callback: [ self answer: false ];
with: 'Cancel' ].
html
span: [ 
html submitButton
callback: [ 
(model where = 'test' and: [ model who = 'staff' ])
ifTrue: [ 
self inform: 'Validation Errors! '.
self answer: false. ]
ifFalse: [ self save ] ];
with: 'Save' ] ]

When I edit a event with an error (eg: model where = 'test' and who = 'staff')
if I click SUBMIT I see my Validation Error! message but the model has been updated!!!

As expected when I click CANCEL the model is not updated.

Michel

On Mon, Oct 3, 2011 at 12:22 PM, James Foster <[hidden email]> wrote:
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

       canvas textInput
               onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique
Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

James Foster-8
Michel,

I'm glad you are investigating Seaside. It is fun to have someone giving feedback on the tutorial.

The Cancel button is given a higher priority by Seaside so that it is evaluated first. If you take an action that prevents other callbacks from running then the domain will not get the updates. I haven't looked in detail, but it may be that by sending #'answer:' in the callback, the other callbacks are not run. (I'd want to do a refresh of the domain or maybe even add a 'Transcript show:' to the other callbacks and verify that they aren't called.) 

See http://joachimtuchel.wordpress.com/2010/03/05/seaside-3-0-and-cancel-buttons/ for Joachim's comments.

James



From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Wednesday, October 5, 2011 5:26:30 AM
Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0

James,

Thanks a lot for the fast answer while I am considering using Seaside for my web development instead JAVA or Ruby :)

No the save method is not call when errors.

I think that I understand what you are just told me... I will try to make  capture new values temporaly in the component and update my model with thoses new values only if I got no errors.

What I do not understing, is when I click CANCEL the change is not applied... and the model should already been updated (as you said)...

Michel

On Wed, Oct 5, 2011 at 1:46 AM, James Foster <[hidden email]> wrote:
Michael,

You say that the model has been updated. I wonder if the entire model was updated or only the portions of the model that are modified by callbacks, including #'what:' and #'where:'? Is the #'save' method called when you get a validation error? Are the #'when:' and #'gameType:' values updated if there is a validation error (these are updated in the #'save' method)?

I believe that the system recognizes a difference between the cancel button and the submit button and behaves differently with respect to the various callbacks. From the point of view of the system, it doesn't know that your submit callback (which runs after the other callbacks) decided that things were invalid. In fact, your submit button callback is explicitly checking the domain values #'where' and #'who', so you should be aware that those values have been updated.

The true/false value returned by #'answer:' is simply an object that is returned by the #'call:' message. It is not meaningful for purposes of applying callbacks (those have already run) or deciding whether the domain should be updated (it is too late). The true/false is simply a value that is used to tell the caller which #'inform:' message to send. The framework doesn't know what meaning you apply to those objects.

If you want to wait to apply new values to the domain model till you have determined that they are valid, then my earlier comment applies:

"To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated." 

That is, modify the callback so that instead of inserting the new value directly into the model, you put it in a new instance variable in the component. Your validation would then look at the instance variables in the component, not in the model. It would not be till the #'save' method that the new values would be copied from the component instance variables to the model.

Let us know if this makes sense. You are asking good questions and I think you are close to understanding how Seaside handles things. 

James


From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Tuesday, October 4, 2011 6:53:49 PM
Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0


Hi

Here my problem from the Gemstone code

LBEventEditor>renderButtonsOn: html
html
div: [ 
html
span: [ 
html cancelButton
callback: [ self answer: false ];
with: 'Cancel' ].
html
span: [ 
html submitButton
callback: [ 
(model where = 'test' and: [ model who = 'staff' ])
ifTrue: [ 
self inform: 'Validation Errors! '.
self answer: false. ]
ifFalse: [ self save ] ];
with: 'Save' ] ]

When I edit a event with an error (eg: model where = 'test' and who = 'staff')
if I click SUBMIT I see my Validation Error! message but the model has been updated!!!

As expected when I click CANCEL the model is not updated.

Michel

On Mon, Oct 3, 2011 at 12:22 PM, James Foster <[hidden email]> wrote:
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

       canvas textInput
               onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique

Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

Jon Paynter-2
Michel,
(and James)

hitting a cancel button (html cancelbutton callback: [ .. ]  )   will not trigger any callbacks other than whatever callback is attached to the cancel button itself.

Also I find when you do "self answer: true."  it behaves like  a return (^true)  in that it exits the method, and anything after that is not run.  >From seaside's point of view, #answer:  is returning a value from a previous #call: statement.

so if you have this:
   self answer: true.
   self halt.   "this will never be called"

you should never see the halt.

On Wed, Oct 5, 2011 at 6:42 AM, James Foster <[hidden email]> wrote:
Michel,

I'm glad you are investigating Seaside. It is fun to have someone giving feedback on the tutorial.

The Cancel button is given a higher priority by Seaside so that it is evaluated first. If you take an action that prevents other callbacks from running then the domain will not get the updates. I haven't looked in detail, but it may be that by sending #'answer:' in the callback, the other callbacks are not run. (I'd want to do a refresh of the domain or maybe even add a 'Transcript show:' to the other callbacks and verify that they aren't called.) 


James



From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Wednesday, October 5, 2011 5:26:30 AM

Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0

James,

Thanks a lot for the fast answer while I am considering using Seaside for my web development instead JAVA or Ruby :)

No the save method is not call when errors.

I think that I understand what you are just told me... I will try to make  capture new values temporaly in the component and update my model with thoses new values only if I got no errors.

What I do not understing, is when I click CANCEL the change is not applied... and the model should already been updated (as you said)...

Michel

On Wed, Oct 5, 2011 at 1:46 AM, James Foster <[hidden email]> wrote:
Michael,

You say that the model has been updated. I wonder if the entire model was updated or only the portions of the model that are modified by callbacks, including #'what:' and #'where:'? Is the #'save' method called when you get a validation error? Are the #'when:' and #'gameType:' values updated if there is a validation error (these are updated in the #'save' method)?

I believe that the system recognizes a difference between the cancel button and the submit button and behaves differently with respect to the various callbacks. From the point of view of the system, it doesn't know that your submit callback (which runs after the other callbacks) decided that things were invalid. In fact, your submit button callback is explicitly checking the domain values #'where' and #'who', so you should be aware that those values have been updated.

The true/false value returned by #'answer:' is simply an object that is returned by the #'call:' message. It is not meaningful for purposes of applying callbacks (those have already run) or deciding whether the domain should be updated (it is too late). The true/false is simply a value that is used to tell the caller which #'inform:' message to send. The framework doesn't know what meaning you apply to those objects.

If you want to wait to apply new values to the domain model till you have determined that they are valid, then my earlier comment applies:

"To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated." 

That is, modify the callback so that instead of inserting the new value directly into the model, you put it in a new instance variable in the component. Your validation would then look at the instance variables in the component, not in the model. It would not be till the #'save' method that the new values would be copied from the component instance variables to the model.

Let us know if this makes sense. You are asking good questions and I think you are close to understanding how Seaside handles things. 

James


From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Tuesday, October 4, 2011 6:53:49 PM
Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0


Hi

Here my problem from the Gemstone code

LBEventEditor>renderButtonsOn: html
html
div: [ 
html
span: [ 
html cancelButton
callback: [ self answer: false ];
with: 'Cancel' ].
html
span: [ 
html submitButton
callback: [ 
(model where = 'test' and: [ model who = 'staff' ])
ifTrue: [ 
self inform: 'Validation Errors! '.
self answer: false. ]
ifFalse: [ self save ] ];
with: 'Save' ] ]

When I edit a event with an error (eg: model where = 'test' and who = 'staff')
if I click SUBMIT I see my Validation Error! message but the model has been updated!!!

As expected when I click CANCEL the model is not updated.

Michel

On Mon, Oct 3, 2011 at 12:22 PM, James Foster <[hidden email]> wrote:
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

       canvas textInput
               onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique


Reply | Threaded
Open this post in threaded view
|

Re: Learning Web Development with Seaside 3.0

Michel Duf
Thank you Jon!

I understand, it work now.

On Wed, Oct 5, 2011 at 4:25 PM, Jon Paynter <[hidden email]> wrote:
Michel,
(and James)

hitting a cancel button (html cancelbutton callback: [ .. ]  )   will not trigger any callbacks other than whatever callback is attached to the cancel button itself.

Also I find when you do "self answer: true."  it behaves like  a return (^true)  in that it exits the method, and anything after that is not run.  >From seaside's point of view, #answer:  is returning a value from a previous #call: statement.

so if you have this:
   self answer: true.
   self halt.   "this will never be called"

you should never see the halt.


On Wed, Oct 5, 2011 at 6:42 AM, James Foster <[hidden email]> wrote:
Michel,

I'm glad you are investigating Seaside. It is fun to have someone giving feedback on the tutorial.

The Cancel button is given a higher priority by Seaside so that it is evaluated first. If you take an action that prevents other callbacks from running then the domain will not get the updates. I haven't looked in detail, but it may be that by sending #'answer:' in the callback, the other callbacks are not run. (I'd want to do a refresh of the domain or maybe even add a 'Transcript show:' to the other callbacks and verify that they aren't called.) 


James



From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Wednesday, October 5, 2011 5:26:30 AM

Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0

James,

Thanks a lot for the fast answer while I am considering using Seaside for my web development instead JAVA or Ruby :)

No the save method is not call when errors.

I think that I understand what you are just told me... I will try to make  capture new values temporaly in the component and update my model with thoses new values only if I got no errors.

What I do not understing, is when I click CANCEL the change is not applied... and the model should already been updated (as you said)...

Michel

On Wed, Oct 5, 2011 at 1:46 AM, James Foster <[hidden email]> wrote:
Michael,

You say that the model has been updated. I wonder if the entire model was updated or only the portions of the model that are modified by callbacks, including #'what:' and #'where:'? Is the #'save' method called when you get a validation error? Are the #'when:' and #'gameType:' values updated if there is a validation error (these are updated in the #'save' method)?

I believe that the system recognizes a difference between the cancel button and the submit button and behaves differently with respect to the various callbacks. From the point of view of the system, it doesn't know that your submit callback (which runs after the other callbacks) decided that things were invalid. In fact, your submit button callback is explicitly checking the domain values #'where' and #'who', so you should be aware that those values have been updated.

The true/false value returned by #'answer:' is simply an object that is returned by the #'call:' message. It is not meaningful for purposes of applying callbacks (those have already run) or deciding whether the domain should be updated (it is too late). The true/false is simply a value that is used to tell the caller which #'inform:' message to send. The framework doesn't know what meaning you apply to those objects.

If you want to wait to apply new values to the domain model till you have determined that they are valid, then my earlier comment applies:

"To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated." 

That is, modify the callback so that instead of inserting the new value directly into the model, you put it in a new instance variable in the component. Your validation would then look at the instance variables in the component, not in the model. It would not be till the #'save' method that the new values would be copied from the component instance variables to the model.

Let us know if this makes sense. You are asking good questions and I think you are close to understanding how Seaside handles things. 

James


From: "Michel Dufour" <[hidden email]>
To: "GemStone Seaside beta discussion" <[hidden email]>
Sent: Tuesday, October 4, 2011 6:53:49 PM
Subject: Re: [GS/SS Beta] Learning Web Development with Seaside 3.0


Hi

Here my problem from the Gemstone code

LBEventEditor>renderButtonsOn: html
html
div: [ 
html
span: [ 
html cancelButton
callback: [ self answer: false ];
with: 'Cancel' ].
html
span: [ 
html submitButton
callback: [ 
(model where = 'test' and: [ model who = 'staff' ])
ifTrue: [ 
self inform: 'Validation Errors! '.
self answer: false. ]
ifFalse: [ self save ] ];
with: 'Save' ] ]

When I edit a event with an error (eg: model where = 'test' and who = 'staff')
if I click SUBMIT I see my Validation Error! message but the model has been updated!!!

As expected when I click CANCEL the model is not updated.

Michel

On Mon, Oct 3, 2011 at 12:22 PM, James Foster <[hidden email]> wrote:
Hi Michael,

Are you interested in doing validation in Smalltalk (on the server) or in Javascript (on the client)? If you want to do it on the client, try adding something like the following to validate a number:

       canvas textInput
               onChange: 'if (isNaN(parseFloat(this.value)) || !isFinite(this.value)) { alert(this.value + " is not a valid number!"); }';

Because you can't control the client completely you should validate on the server even if you have client-side validation. To do that you could capture new values in an instance variable on your component and wait to apply them to the domain model till all fields have been validated.

James

On Oct 3, 2011, at 8:07 AM, Michel Duf wrote:

> Hi
>
> Is there a easy way to add field validation in the form example provided in
> the Gemstone seaside tutorial?
>
> Thanks
> Michel
>
> --
> View this message in context: http://forum.world.st/Learning-Web-Development-with-Seaside-3-0-tp3867781p3867781.html
> Sent from the GLASS mailing list archive at Nabble.com.




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique




--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique





--
Merci
Michel Dufour

Conseiller Sénior en Technologies
[hidden email]
www.everestinformatique.com
Everest Informatique inc.
Membre www.acm.org :http://member.acm.org/~everestinformatique