Hi everyone!
I have a question about validating models with Magritte. When i add a condition to a magritte's description, the condition references the value. For example: SomeClass class>>descriptionFoo ^ (MAStringDescription auto: 'foo label: 'Foo' priority: '10') addCondition: [:value | some value checking] labelled: 'Invalid something'; yourself. In SomeClass i have many descriptions and i want to do some validations combining two or more descriptions. I don't know if this is the way to do this. Thanks in advance :D _______________________________________________ Seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
> Hi everyone!
> > I have a question about validating models with Magritte. > When i add a condition to a magritte's description, the > condition references the value. For example: > > SomeClass class>>descriptionFoo > ^ (MAStringDescription > auto: 'foo > label: 'Foo' > priority: '10') > addCondition: [:value | some value checking] > labelled: 'Invalid something'; > yourself. > > In SomeClass i have many descriptions and i want to do some > validations combining two or more descriptions. > I don't know if this is the way to do this. > > Thanks in advance :D I just learned this one myself, you put the rule on the container description using the other descriptions as the key into the value cache like so.. descriptionContainer ^(super descriptionContainer) addCondition: [:value | (value cache at: self descriptionStartDate) < (value cache at: self descriptionEndDate)] labelled: 'Start date must be before end date'; yourself Ramon Leon http://onsmalltalk.com _______________________________________________ Seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
Thanks Ramon! It works great!!
One last question about conditions. How can i override the default message for beRequired? When i add a custom condition i specify it with the labelled: argument. Or maybe better.. give localizated messages.. am i asking too much? xD Thanks again P.D.: onsmalltalk.com it's great! Awesome writing :D On 11/13/06, Ramon Leon <[hidden email]> wrote: > > Hi everyone! > > > > I have a question about validating models with Magritte. > > When i add a condition to a magritte's description, the > > condition references the value. For example: > > > > SomeClass class>>descriptionFoo > > ^ (MAStringDescription > > auto: 'foo > > label: 'Foo' > > priority: '10') > > addCondition: [:value | some value checking] > > labelled: 'Invalid something'; > > yourself. > > > > In SomeClass i have many descriptions and i want to do some > > validations combining two or more descriptions. > > I don't know if this is the way to do this. > > > > Thanks in advance :D > > I just learned this one myself, you put the rule on the container > description using the other descriptions as the key into the value cache > like so.. > > descriptionContainer > ^(super descriptionContainer) > addCondition: > [:value | > (value cache at: self descriptionStartDate) > < (value cache at: self descriptionEndDate)] > labelled: 'Start date must be before end date'; > yourself > > Ramon Leon > http://onsmalltalk.com > > _______________________________________________ > 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 |
>
> Thanks Ramon! It works great!! > > One last question about conditions. How can i override the > default message for beRequired? When i add a custom condition > i specify it with the labelled: argument. > > Or maybe better.. give localizated messages.. am i asking too much? xD > > Thanks again > > P.D.: onsmalltalk.com it's great! Awesome writing :D Thanks, glad it's useful. As for beRequired, you got me there, no clue, maybe someone else will chime in with the answer. Ramon Leon http://onsmalltalk.com _______________________________________________ Seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
> Thanks, glad it's useful. As for beRequired, you got me there, no clue,
> maybe someone else will chime in with the answer. The latest version of Magritte (Magritte-All-lr.179 or later) has properties to set the error text for specific error, e.g. #conflictErrorMessage:, #kindErrorMessage:, #multipleErrorsMessage:, #requiredErrorMessage: and #rangeErrorMessage:. The latest version of Pier also makes use of this new feature and now displays much nicer error messages. Note that you are required to load Seaside2.7 to use this version of Magritte. 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 |
On 11/14/06, Lukas Renggli <[hidden email]> wrote:
> > Thanks, glad it's useful. As for beRequired, you got me there, no clue, > > maybe someone else will chime in with the answer. > > The latest version of Magritte (Magritte-All-lr.179 or later) has > properties to set the error text for specific error, e.g. > #conflictErrorMessage:, #kindErrorMessage:, #multipleErrorsMessage:, > #requiredErrorMessage: and #rangeErrorMessage:. > It works great! Thanks Lukas! And descriptionContainer ^(super descriptionContainer) addCondition: [:value | (value cache at: self descriptionStartDate) < (value cache at: self descriptionEndDate)] labelled: 'Start date must be before end date'; yourself Worked great Ramon! But how can i validate the unicity of an object in a collection but inside a description? is this possible? the idea is to keep the validation inside the description throw addContition:labelled: Thanks again :) _______________________________________________ Seaside mailing list [hidden email] http://lists.squeakfoundation.org/cgi-bin/mailman/listinfo/seaside |
> But how can i validate the unicity of an object in a collection but
> inside a description? is this possible? the idea is to keep the > validation inside the description throw addContition:labelled: Depends on your actual setup. In MAMultipleOptionDescription there is a #distinct: property that enforces uniqueness by using a Set. If you have a MAToManyRelationDescription you can add a condition like: [ :coll | coll asSet size = coll size ] If you want to check if an object is not existing yet (such as the sub-domain name of a seasidehosting.st account), you can use something like that: descriptionName ^ (MAStringDescription selector: #name label: 'Name' priority: 10) addCondition: [ :value | value size > 2 ] labelled: 'The site-name is too short, please use a longer one'; addCondition: [ :value | value isValidSiteName ] labelled: 'The site-name is invalid, please only use alpha-nummerical characters'; " here we check for the uniqueness of the domain name " addCondition: [ :value | (SHRoot default accounts includesKey: value asLowercase) not or: [ SHSettings serviceDirectory includesKey: value asLowercase ] ] labelled: 'The name is already taken, please choose a different one'; beRequired; yourself. 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 |
Free forum by Nabble | Edit this page |