Created
September 11, 2010 00:21
-
-
Save brentonashworth/574594 to your computer and use it in GitHub Desktop.
Sandbar forms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Use sandbar to create forms. Create routes, validate input, display error messages, | |
;; marshal form data, etc. More documentation and examples coming soon. | |
(defn password-strength [m] | |
(if (< (count (:password m)) 10) | |
(add-validation-error m :password properties) | |
m)) | |
(def validator | |
(build-validator | |
(non-empty-string :username :password :first-name :last-name :email | |
properties) | |
:ensure | |
password-strength)) | |
(forms/defform user-form "/user/edit" | |
:fields [(hidden :id) | |
(textfield :username) | |
(password :password) | |
(textfield :first-name :last-name :email) | |
(checkbox :account-enabled) | |
(multi-checkbox :roles (db/all-roles) name) | |
(select :region | |
(db/all-regions) | |
{:id :value :prompt {"" "Select a Region"}})] | |
:buttons [[:save] [:cancel]] | |
:load #(db/find-user %) | |
:on-cancel "/" | |
:on-success | |
#(do | |
(db/store-user %) | |
(set-flash-value! :user-message "User has been saved.") | |
"/") | |
:validator validator | |
:properties properties | |
:field-layout [1 1 2 1 1 1]) | |
(defroutes routes | |
(user-form (fn [_ form] (layout form)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment