@@ -3,6 +3,7 @@ module Reflex.Dom.Extra where
33
44import Control.Lens
55import Control.Monad.Fix
6+import Data.Char
67import Data.Either
78import Data.Map as M
89import Data.Maybe
@@ -252,12 +253,18 @@ inputMonth
252253 :: (MonadFix m, DomBuilder t m, MonadHold t m)
253254 => InputElementConfig er t (DomBuilderSpace m)
254255 -> m (InputElement er (DomBuilderSpace m) t)
255−inputMonth ec = inputCorrect correct $ ec
256+inputMonth ec = inputCorrect correct2 $ ec
256257 & initialAttributes %~ (<> "type" =: "text" <> "maxlength" =: "5")
257258 where
258− correct ov nv = case (T.length ov, T.length nv) of
259− (x,2) | x < 2 -> nv <> "/"
260− (x,3) | x > 3 -> T.take 2 nv
261− (_, x) | x > 2 && T.head (T.drop 2 nv) /= '/' ->
262− T.take 5 $ T.take 2 nv <> "/" <> T.drop 2 nv
263− _ -> nv
259+ correct2 (T.length -> ol) (T.foldl' f "" -> nv)
260+ | ol < 2 && nl == 2 = nv `T.snoc` '/'
261+ | ol > 3 && nl == 3 = T.init nv
262+ | otherwise = nv
263+ where
264+ nl = T.length nv
265+ f r c
266+ | (lr == 2 && isDigit c) = r `T.snoc` '/' `T.snoc` c
267+ | (lr == 2 && c == '/') || (isDigit c && lr < 5) = T.snoc r c
268+ | otherwise = r
269+ where
270+ lr = T.length r