I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
..I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the attributes list.
Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.
Thank you Klausk,..
Yes, TypeConvertier looks like the right place to capture user input and validate it. It was easy to intercept the conversion in #rightToLeft: and call a validation method, as in the following:
NumberToText>>rightToLeft: aString
"Answers the result of converting aString to a Number."
| newNumber |
newNumber := Number fromString: aString.
^newNumber := self validateOrKeep: newNumber.
NumberToText>>validateOrKeep: newNumber
"Validate the new number or keep the current <oldNumber> unchanged"
| min max oldNumber |
oldNumber := 'obtain it from TextEdit model'.
min := 'calculate it'.
max := 'calculate it'.
^(newNumber between: min and: max) ifTrue: [newNumber] ifFalse: [oldNumber]
In the above, <oldNumber>, <min> and <max> all of them depend on the current status of the model; <NumberToText> converter needs a way to communicate back with its <TextEdit> to obtain them.
How do I do that?
Thanks for reading and eventually answering.
FB
___________________________________________
On Sat, 23 Jan 2021 at 11:02, klausk <in...@kirchhoff-edv.de> wrote:
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the attributes list.
Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.list...
On Saturday, January 23, 2021 at 11:02:51 AM UTC+2, klausk wrote:
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the attributes
Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.
I notice you mention "buffering presenter", but—at least, the way I know how to do it—really it's not the Presenter that does the buffering, but a wrapper on top of the model. Check out <AspectBuffer>—you could take an approach where your modelclass *allows* itself to become invalid, but can answer whether it is valid and if not, why not. The presenter can display messages accordingly, and only flush the updated values to the "subject" of the buffer (the original model) if they are valid—
I generally wouldn't use a TypeConverter for complex semantic validation—only for what essentially amounts to text formatting, i.e. restricting to numbers. It can be very disconcerting to a user to have some keystrokes appear to be simply ignored, ifthe reasoning is not immediately and blatantly obvious. Much better to allow them through, display what was typed and explain exactly why it is not valid.
On Saturday, January 23, 2021 at 8:39:36 AM UTC-5, fbek...@gmail.com wrote:list...
Thank you Klausk,
Yes, TypeConvertier looks like the right place to capture user input and validate it. It was easy to intercept the conversion in #rightToLeft: and call a validation method, as in the following:
NumberToText>>rightToLeft: aString
"Answers the result of converting aString to a Number."
| newNumber |
newNumber := Number fromString: aString.
^newNumber := self validateOrKeep: newNumber.
NumberToText>>validateOrKeep: newNumber
"Validate the new number or keep the current <oldNumber> unchanged"
| min max oldNumber |
oldNumber := 'obtain it from TextEdit model'.
min := 'calculate it'.
max := 'calculate it'.
^(newNumber between: min and: max) ifTrue: [newNumber] ifFalse: [oldNumber]
In the above, <oldNumber>, <min> and <max> all of them depend on the current status of the model; <NumberToText> converter needs a way to communicate back with its <TextEdit> to obtain them.
How do I do that?
Thanks for reading and eventually answering.
FB
___________________________________________
On Sat, 23 Jan 2021 at 11:02, klausk <in...@kirchhoff-edv.de> wrote:
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the attributes
list...Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.
On Saturday, January 23, 2021 at 11:02:51 AM UTC+2, klausk wrote:
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the attributes
Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.
Thanks for the feedback, yes, "buffering presenter" was misleading and your description of an <AspectBuffer> wrapper on top of the model is correct. But I don't really need to buffer the whole model though, as most of the time working directly with themodel is fine. And I have looked at <Dialog> #model: which readily works with a buffered model, for some idea about how this is done. I could therefore try and learn something else maybe.
So I think I will investigate a way to buffer only the 2 values of interest, directly in the Presenter or through an AspectBuffer - and use the buffer as fallback or to calculate validations - and see how it goes.on the purpose of the application - a direct Presenter-View connected to the model (as in this case) may have different validation requirements compared to when the model is plugged into a larger application, as a specialized module (as in a future case).
On another note, and in order to ensure the model is reusable, I think I should limit the model exception/error handling to those cases that would break the calculations only, while basic validation of input is handled closer to the user, and depends
I now realize also that <TypeConverter> may not be the best place to do the validation, and anyway, due to encapsulation of data, it does not seem to have access to the model - unless there IS a way?class *allows* itself to become invalid, but can answer whether it is valid and if not, why not. The presenter can display messages accordingly, and only flush the updated values to the "subject" of the buffer (the original model) if they are valid—
Going backward one step, <TextEdit> would be the next candidate, but I would hate to mess up with <TextEdit>'s core methods for #apply; #updateModel; and, super #updateModel (where the call for - and the return of - the TypeConverter. takes place).
That brings me back to the Presenter itself, and if I manage to buffer those 2 values, I can let the presenter do all sorts of validations, and if the model becomes temporarily invalid, then be it, as you said, until the user keys in another value...
Your further comments and feedback would be appreciated.
FB
___________________________________________
On Sunday, January 24, 2021 at 1:10:20 AM UTC+2, danie...@gmail.com wrote:
I notice you mention "buffering presenter", but—at least, the way I know how to do it—really it's not the Presenter that does the buffering, but a wrapper on top of the model. Check out <AspectBuffer>—you could take an approach where your model
if the reasoning is not immediately and blatantly obvious. Much better to allow them through, display what was typed and explain exactly why it is not valid.I generally wouldn't use a TypeConverter for complex semantic validation—only for what essentially amounts to text formatting, i.e. restricting to numbers. It can be very disconcerting to a user to have some keystrokes appear to be simply ignored,
list...On Saturday, January 23, 2021 at 8:39:36 AM UTC-5, fbek...@gmail.com wrote:
Thank you Klausk,
Yes, TypeConvertier looks like the right place to capture user input and validate it. It was easy to intercept the conversion in #rightToLeft: and call a validation method, as in the following:
NumberToText>>rightToLeft: aString
"Answers the result of converting aString to a Number."
| newNumber |
newNumber := Number fromString: aString.
^newNumber := self validateOrKeep: newNumber.
NumberToText>>validateOrKeep: newNumber
"Validate the new number or keep the current <oldNumber> unchanged"
| min max oldNumber |
oldNumber := 'obtain it from TextEdit model'.
min := 'calculate it'.
max := 'calculate it'.
^(newNumber between: min and: max) ifTrue: [newNumber] ifFalse: [oldNumber]
In the above, <oldNumber>, <min> and <max> all of them depend on the current status of the model; <NumberToText> converter needs a way to communicate back with its <TextEdit> to obtain them.
How do I do that?
Thanks for reading and eventually answering.
FB
___________________________________________
On Sat, 23 Jan 2021 at 11:02, klausk <in...@kirchhoff-edv.de> wrote:
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the attributes
attributes list...Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.
On Saturday, January 23, 2021 at 11:02:51 AM UTC+2, klausk wrote:
I would like, however, to validate the input on a few cells, to prevent the user from keying in values outside a dynamic range, that do not make sense in a given context, even if not causing a system error.
I let a TypeConverter do this for me if values have to be eg. currencies. Invalid values are suppressed. It then looks like "the computer hoesn't like my input". When editing a TextEdit inside the ViewComposer, look at the bottom of the
Otherwise try ChoicePresenter. If values are in a range have a look at Spinner.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 293 |
Nodes: | 16 (2 / 14) |
Uptime: | 216:42:39 |
Calls: | 6,621 |
Calls today: | 3 |
Files: | 12,169 |
Messages: | 5,317,616 |