Easy Form Validation

Started by docsaintly, August 07, 2009, 09:01:03 PM

Previous topic - Next topic

docsaintly

I have a form with about 15 text boxes, 5 check boxes, 2 radio buttons. Validating the text boxes is obviously the largest task. I found a great way to define all of the text boxes. I only wanted float numbers, so I wrote a function that returns a float number from a fraction string or float string. To apply this same function to all my text boxes i used a foreach + eval + read. See below:

Code (autolisp) Select

(defun txtValidateFuncs (/ functionstrings functions varFunc StringFilter)
(dcl_messagebox "validate has been run" "")
(setq StringFilter "0123456789./")
;"txtOrigin"
;"txtRows"
;"txtColumns"
(setq functionstrings
(list
"txtCellX"
"txtCellY"
"txtTextX"
"txtTextY"
"txtTextULX"
"txtTextULY"
"txtRowOffset"
"txtColumnOffset"
"txtGridXOffset"
"txtGridYOffset"
"txtBlockX"
"txtBlockY"
"txtBlockULX"
"txtBlockULY"
"txtXSize"
)
)


(foreach varFunc functionstrings
(eval
(read
(strcat "(dcl_TextBox_SetFilter " varFunc " \"" StringFilter "\")"
"(defun c:" varFunc "_OnKillFocus (/)
(if (not(validateFloatInput (dcl_Control_GetText " varFunc ")))
(progn
(dcl_messagebox \"Please enter a decimal or a fraction.\" \"Invalid Value!\")
(dcl_Control_SetFocus " varFunc ")
)
)
)
")
)
)
)
)

Kerry


Have a look at the FilterStyle property of the Textbox ...

Style Description
0 Non-control characters (or custom filter)
1 AutoCAD angle units only
2 Signed integers only
3 AutoCAD distance units only (affected by DIMZIN system variable)
4 AutoCAD symbol table names only
5 Upper case only
6 Lower case only
7 Password (hides input text)
8 All characters allowed (including [Enter])


/// kdub
Perfection is not optional.
My other home is TheSwamp

docsaintly

Thanks for the advice, but this was used to overcome a limitation of the textbox FilterStyle. Also, this could be useful for things other than textboxes. The main objective of this isn't that it validates data, it's that it creates numerous functions with different names but the same content. This way if you want to change how a typical object type reacts, you change it one place instead of 20, 30, or however many types of that object you have.

mkweaver

I love to see lisp routines that create lisp routines :)