addCondition:labelled:

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

addCondition:labelled:

Joel Turnbull

addCondition:labelled does not seem to be working the way I expected.

I just want to validate that a given text field is not empty

I have a description definition method and setter:

descriptionTags
^MAStringDescription new
    selectorAccessor: #tagsConverter;
    label: 'Tags';
    priority: 40;
    addCondition: [:value | value notEmpty ]
        labelled: 'Please provide at least one tag';
    yourself

tagsConverter: aString
    tags := aString asUppercase subStrings asSet

On submit, I get an error that nil does not understand asUppercase. Shouldn't the condition fail before the setter is called? I've tried [ :value | value notNil ], and beRequired as well, got the same error. I also tried to change the initialize method of the object I'm describing to set tags to an empty collection but that didn't work either.

Thanks,
Joel






_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: addCondition:labelled:

Lukas Renggli
> I just want to validate that a given text field is not empty

Normally sending #beRequired to the description should be enough. At
least with my Seaside forms this works well and there is no need to
add an additional check for #isEmpty.

> On submit, I get an error that nil does not understand asUppercase.
> Shouldn't the condition fail before the setter is called?

#beRequired ensures that a nil or empty value is not committed.
Additional conditions will not be evaluated (there are various
examples of this in Pier, for example).

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch
_______________________________________________
Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki