on develop help sign in
dropdownDynAttr
commit70ebea06a30088da2845f59bdaf372f4c5e62445 authorali abrar <aliabrar@gmail.com> dateWed 4 Mar 2015, 18:45 (12 years ago) parentc51bac3
1 file changed+6−4
src/Reflex/Dom/Widget/Input.hs+6−4
src/Reflex/Dom/Widget/Input.hs+6−4
@@ -219,13 +219,12 @@ data Dropdown t k
219219 }
220220
221221--TODO: We should allow the user to specify an ordering instead of relying on the ordering of the Map
222−--TODO: Don't bake in any CSS classes
223222--TODO: Get rid of Show k and Read k by indexing the possible values ourselves
224223-- | Create a dropdown box
225224-- The first argument gives the initial value of the dropdown; if it is not present in the map of options provided, it will be added with an empty string as its text
226−dropdown :: forall k t m. (MonadWidget t m, Ord k, Show k, Read k) => k -> Dynamic t (Map k String) -> m (Dropdown t k)
227−dropdown k0 options = do
228− (eRaw, _) <- elAttr' "select" ("class" =: "form-control") $ do
225+dropdownDynAttr :: forall k t m. (MonadWidget t m, Ord k, Show k, Read k) => Dynamic t (Map String String) -> k -> Dynamic t (Map k String) -> m (Dropdown t k)
226+dropdownDynAttr attrs k0 options = do
227+ (eRaw, _) <- elDynAttr' "select" attrs $ do
229228 optionsWithDefault <- mapDyn (`Map.union` (k0 =: "")) options
230229 listWithKey optionsWithDefault $ \k v -> do
231230 elAttr "option" ("value" =: show k <> if k == k0 then "selected" =: "selected" else mempty) $ dynText v
@@ -240,6 +239,9 @@ dropdown k0 options = do
240239 dValue <- combineDyn readKey options =<< holdDyn (Just k0) eChange
241240 return $ Dropdown dValue
242241
242+dropdown :: forall k t m. (MonadWidget t m, Ord k, Show k, Read k) => k -> Dynamic t (Map k String) -> m (Dropdown t k)
243+dropdown = dropdownDynAttr (constDyn Map.empty)
244+
243245--TODO: Get rid of Show k and Read k by indexing the possible values ourselves
244246dropdown' :: forall k t m. (MonadWidget t m, Eq k, Show k, Read k) => k -> NonEmpty (k, String) -> m (Dropdown t k)
245247dropdown' k0 ks = do