Skip to content

Instantly share code, notes, and snippets.

@mightybyte
Created January 19, 2011 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mightybyte/786236 to your computer and use it in GitHub Desktop.
Save mightybyte/786236 to your computer and use it in GitHub Desktop.
Passes a depth to addItem
diff --git a/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs b/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs
index 88b5510..4d647af 100644
--- a/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs
+++ b/digestive-functors-blaze/src/Text/Digestive/Blaze/Html5.hs
@@ -41,6 +41,7 @@ import Text.Digestive.Forms (FormInput (..))
import qualified Text.Digestive.Forms as Forms
import qualified Text.Digestive.Common as Common
import Text.Digestive.Forms.Html
+import Text.Digestive.Result
import Text.Digestive.Transform
-- | Form HTML generated by blaze
@@ -240,7 +241,7 @@ inputList :: (Monad m, Functor m, FormInput i f)
-> Formlet m i e BlazeFormHtml [a]
-- ^ The dynamic list formlet
inputList hidden single d =
- mapView (fmap (addControls $ H.stringValue "this")) $ Forms.inputList hidden s d
+ mapView (fmap (addControls $ H.stringValue "3")) $ Forms.inputList hidden s d
where
s def = mapView (fmap (H.div ! A.class_ "inputListItem")) $ single def
@@ -256,11 +257,10 @@ inputList' hidden single d = Form $ do
state <- get
singleView <- liftM fst $ unForm $ single Nothing
let fh = unView singleView []
+ (FormRange rangeStart _) = state
+ depth = H.stringValue $ show $ length $ formIdList rangeStart
f (FormHtml enc hfunc) = FormHtml enc $
- \cfg -> addControls (mconcat [H.preEscapedStringValue "'"
- ,H.stringValue $ renderHtml $ formHtml fh cfg
- ,H.preEscapedStringValue "'"])
- (hfunc cfg)
+ \cfg -> addControls depth (hfunc cfg)
put state
unForm $ mapView f $ Forms.inputList hidden s d
where
@@ -270,7 +270,7 @@ addControls param form = do
H.div ! A.class_ "inputList" $ do
H.div $ do
H.input ! A.type_ "button"
- ! A.onclick (mconcat ["alert(",param,"); return false;"])
+ ! A.onclick (mconcat ["addItem(this, ",param,"); return false;"])
! A.value "Add Item"
H.input ! A.type_ "button"
! A.onclick "removeItem(this); return false;"
@@ -294,7 +294,7 @@ inputListJs = unlines
," return $('.inputListItem', findInputList(button));"
,"}"
,""
- ,"function addItem(button) {"
+ ,"function addItem(button, depth) {"
," var count = $(':hidden', findInputList(button))[0];"
," var items = findItems(button);"
," var item = $(items[items.length-1]);"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment