~alcinnz/bureaucromancy

989db10633271470147fddcdf7c1c0d2a35babe8 — Adrian Cochrane 1 year, 29 days ago b72e3a0
Integrate normalization tighter into normalization.
2 files changed, 16 insertions(+), 4 deletions(-)

M bureaucromancy.cabal
M src/Text/HTML/Form/Validate.hs
M bureaucromancy.cabal => bureaucromancy.cabal +2 -2
@@ 65,7 65,7 @@ library
    exposed-modules:  Text.HTML.Form, Text.HTML.Form.Query,
        Text.HTML.Form.WebApp, Text.HTML.Form.WebApp.Ginger,
        Text.HTML.Form.WebApp.Ginger.Hourglass, Text.HTML.Form.WebApp.Ginger.TZ,
        Text.HTML.Form.Colours
        Text.HTML.Form.Colours, Text.HTML.Form.Validate

    -- Modules included in this library but not exported.
    -- other-modules:


@@ 76,7 76,7 @@ library
    -- Other library packages from which modules are imported.
    build-depends:    base ^>=4.16.4.0, ginger, file-embed-lzma, file-embed, mtl,
            bytestring, text, xml-conduit, network-uri, regex-tdfa, containers,
            filepath, directory, hourglass >= 0.2.12 && < 0.3, tz >= 0.1 && < 0.2
            filepath, directory, hourglass >= 0.2.12 && < 0.3, tz >= 0.1 && < 0.2,

    -- Directories containing source files.
    hs-source-dirs:   src

M src/Text/HTML/Form/Validate.hs => src/Text/HTML/Form/Validate.hs +14 -2
@@ 1,6 1,6 @@
{-# LANGUAGE OverloadedStrings #-}
module Text.HTML.Form.Validate(
        isInputValid, isFormValid, inputErrorMessage, normalizeInput) where
module Text.HTML.Form.Validate(isInputValid, isInputValid', isFormValid, isFormValid',
        inputErrorMessage, inputErrorMessage', normalizeInput, normalizeForm) where

import Text.HTML.Form
import qualified Data.Text as Txt


@@ 13,9 13,15 @@ import Text.Regex.TDFA ((=~), matchTest)
isFormValid :: Form -> Bool
isFormValid = all isInputValid . inputs

isFormValid' :: Form -> Bool
isFormValid' = all isInputValid' . inputs

isInputValid :: Input -> Bool
isInputValid = null . inputErrorMessage

isInputValid' :: Input -> Bool
isInputValid' = null . inputErrorMessage'

inputErrorMessage :: Input -> [Char]
inputErrorMessage Input { inputType = "hidden" } = "" -- Don't validate hiddens!
inputErrorMessage self@Input { required = True }


@@ 82,6 88,9 @@ inputErrorMessage self@Input { inputType = "url" }
inputErrorMessage self@Input { inputType = "week" } = isTime' self
inputErrorMessage _ = ""

inputErrorMessage' :: Input -> [Char]
inputErrorMessage' = inputErrorMessage . normalizeInput

parseTime :: String -> Maybe DateTime
parseTime = fmap localTimeUnwrap . localTimeParse ISO8601_DateAndTime
isTime :: Input -> Bool


@@ 101,3 110,6 @@ normalizeInput self@Input { inputType = "url", value = val }
        }
-- Other aspects we wish to normalize?
normalizeInput self = self

normalizeForm :: Form -> Form
normalizeForm self = self { inputs = map normalizeInput $ inputs self }