{-# LANGUAGE RecordWildCards #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE QuasiQuotes #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE CPP #-} -- | A module providing a means of creating multiple input forms without -- the need to submit the form to generate a new input field unlike -- in "MassInput". module Yesod.Form.MultiInput ( MultiSettings (..) , MultiView (..) , mmulti , amulti , bs3Settings , bs3FASettings , bs4Settings , bs4FASettings ) where import Control.Arrow (second) import Control.Monad (liftM) import Control.Monad.Trans.RWS (ask, tell) import qualified Data.Map as Map import Data.Maybe (fromJust, listToMaybe, fromMaybe, isJust) import Data.Text (Text) import qualified Data.Text as T import Text.Julius (rawJS) import Yesod.Core import Yesod.Form.Fields (intField) import Yesod.Form.Functions import Yesod.Form.Types #ifdef MIN_VERSION_shakespeare(2,0,18) #if MIN_VERSION_shakespeare(2,0,18) #else import Text.Julius (ToJavascript (..)) instance ToJavascript String where toJavascript = toJavascript . toJSON instance ToJavascript Text where toJavascript = toJavascript . toJSON #endif #endif -- | By default delete buttons have a @margin-left@ property of @0.75rem@. -- You can override this by specifying an alternative value in a class -- which is then passed inside 'MultiSettings'. -- -- @since 1.7.0 data MultiSettings site = MultiSettings { msAddClass :: !Text -- ^ Class to be applied to the "add another" button. , msDelClass :: !Text -- ^ Class to be applied to the "delete" button. , msTooltipClass :: Text -- ^ Only used in applicative forms. Class to be applied to the tooltip. , msWrapperErrClass :: !Text -- ^ Class to be applied to the wrapper if it's field has an error. , msAddInner :: !(Maybe Html) -- ^ Inner Html of add button, defaults to "Add Another". Useful for adding icons inside buttons. , msDelInner :: !(Maybe Html) -- ^ Inner Html of delete button, defaults to "Delete". Useful for adding icons inside buttons. , msErrWidget :: Maybe (Html -> WidgetFor site ()) -- ^ Only used in applicative forms. Create a widget for displaying errors. } -- | The general structure of each individually generated field is as follows. -- There is an external wrapper element containing both an inner wrapper and any -- error messages that apply to that specific field. The inner wrapper contains -- both the field and it's corresponding delete button. -- -- The structure is illustrated by the following: -- -- >