Field's length
[1/5] from: brasilv::tin::it at: 12-Dec-2005 14:49
Hi List,
I've got one, simple (hope), question for you.
I need to manage input and I would like to know if 'field could be set with
a max length to make sure that when I'll write my data on the DB, strings
will be non longer than what defined in my table.
If a refinement like this exists, how is called? If there's no such a
refinement is there a little function I can use to control my input or
should I write it alone?
Thank you, Silvia
[2/5] from: tim-johnsons:web at: 12-Dec-2005 11:35
* Silvia Brandimarte <brasilv-tin.it> [051212 05:03]:
> Hi List,
> I've got one, simple (hope), question for you.
<<quoted lines omitted: 5>>
> should I write it alone?
> Thank you, Silvia
Hi Silvia:
From this posting I'm not sure which DB scheme you are using.
There are many different approaches to use, most Databases
have field descriptions which contain sizes:
example: in Mysql char(30)
One could query the database description, then parse
the field/column description.
So, first tell us what DB interface you're using.
HTH
tim
> --
> To unsubscribe from the list, just send an email to
> lists at rebol.com with unsubscribe as the subject.
--
Tim Johnson <tim-johnsons-web.com>
http://www.alaska-internet-solutions.com
[3/5] from: louisgosselin:accesrail at: 12-Dec-2005 15:46
Silvia,
You need to patch the feel object of your field so that engage takes
the max length into account when it processes keyboard input.
Here is a rough example of a field which stops accepting characters
after the 10th. You could include something similar in your style definition
lt: layout [
mxfld: field feel [
engage: func [face act event] [
switch act [
down [
either not-equal? face system/view/focal-face [
focus face
system/view/caret: offset-to-caret face event/offset
] [
system/view/highlight-start:
system/view/highlight-end: none
system/view/caret: offset-to-caret face event/offset
]
show face
]
over [
if not-equal? system/view/caret offset-to-caret
face event/offset [
if not system/view/highlight-start
[system/view/highlight-start: system/view/caret]
system/view/highlight-end:
system/view/caret: offset-to-caret face event/offset
show face
]
]
key [
if any [
face/max-len > length? face/text
event/key = #"^M"
event/key = #"^~"
event/key = #"^H"
event/key = #"^-"
event/key = 'left
event/key = 'right
] [
system/words/ctx-text/edit-text face event
get in face 'action
]
]
]
]
] with [max-len: 10]
]
view lt
I use something similar in my style definition
Hope this help,
Louis
At 08:49 AM 2005-12-12, you wrote:
[4/5] from: tim-johnsons::web::com at: 12-Dec-2005 14:05
* Louis Gosselin <louisgosselin-accesrail.com> [051212 11:55]:
>
> Silvia,
>
> You need to patch the feel object of your field so that engage takes
Oops! Sorry. Looks like this is a /view question....
tj
--
Tim Johnson <tim-johnsons-web.com>
http://www.alaska-internet-solutions.com
[5/5] from: antonr::lexicon::net at: 13-Dec-2005 17:22
Try code at bottom:
Anton.
> Hi List,
> I've got one, simple (hope), question for you.
<<quoted lines omitted: 6>>
> should I write it alone?
> Thank you, Silvia
view layout [
style limited-field field with [
max-length: none ; default is no limit (change this to your desired
default)
feel: make feel [] ; clone the feel so we modify only a copy
; add some code after the key handler, binding to 'face
use [blk][
blk: last third second get in feel 'engage ; the block in which edit-text
is called
append blk bind [
if all [
face/max-length
face/max-length < length? face/text
][
clear skip face/text face/max-length
if all [ ; caret needs fixing?
same? head system/view/caret head face/text
(index? system/view/caret) > face/max-length
][
system/view/caret: at system/view/caret face/max-length
]
show face
]
] blk/2 ; 'face
]
]
field
limited-field
limited-field with [max-length: 3]
limited-field with [max-length: 10]
]
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted