]> gitweb.factorcode.org Git - factor.git/commitdiff
Merge branch 'master' of git://factorcode.org/git/jamesnvc
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 13 Jan 2009 23:44:17 +0000 (17:44 -0600)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Tue, 13 Jan 2009 23:44:17 +0000 (17:44 -0600)
basis/validators/validators-docs.factor
basis/validators/validators-tests.factor
basis/validators/validators.factor

index 4f03fa915b8b53b2672bb5115cb624141af0361c..67c9f4fcebd79569f5ade9f20718ade9f0020b3e 100644 (file)
@@ -2,6 +2,10 @@ USING: help.markup help.syntax io.streams.string quotations
 strings math regexp regexp.backend ;
 IN: validators
 
+HELP: v-checkbox
+{ $values { "str" string } }
+{ $description "Converts the string value of a checkbox component (either \"on\" or \"off\") to a boolean value." } ;
+
 HELP: v-captcha
 { $values { "str" string } }
 { $description "Throws a validation error if the string is non-empty. This is used to create bait fields for spam-bots to fill in." } ;
@@ -99,6 +103,7 @@ $nl
 { $subsection v-one-line    }
 { $subsection v-one-word    }
 { $subsection v-captcha     }
+{ $subsection v-checkbox    }
 "More complex validators:"
 { $subsection v-email       }
 { $subsection v-url         }
index d4f3487d0b9c83cb4f96674eeeef87394f336702..acdcdda5d2b27954b3b7732cd13adafe55de4826 100644 (file)
@@ -10,6 +10,9 @@ namespaces assocs ;
 [ "hello" ] [ "hello" v-one-word ] unit-test
 [ "hello world" v-one-word ] must-fail
 
+[ t ] [ "on" v-checkbox ] unit-test
+[ f ] [ "off" v-checkbox ] unit-test
+
 [ "foo" v-number ] must-fail
 [ 123 ] [ "123" v-number ] unit-test
 [ 123 ] [ "123" v-integer ] unit-test
index a70e20d7b6c7b28d112dcd4972986d3493705fde..04c85cd6db602fc48ebdad30602c7b534ff249d8 100644 (file)
@@ -5,6 +5,9 @@ math.parser math.ranges assocs regexp unicode.categories arrays
 hashtables words classes quotations xmode.catalog ;
 IN: validators
 
+: v-checkbox ( str -- ? )
+    "on" = ;
+
 : v-default ( str def -- str/def )
     over empty? spin ? ;