on develop help sign in
dropdownDynAttr
70ebea0ali abrar
src/Reflex/Dom/Widget/Input.hs+6−4
@@ -219,13 +219,12 @@ data Dropdown t k
219 }
219 }
220
220
221--TODO: We should allow the user to specify an ordering instead of relying on the ordering of the Map
221--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
223--TODO: Get rid of Show k and Read k by indexing the possible values ourselves
222--TODO: Get rid of Show k and Read k by indexing the possible values ourselves
224-- | Create a dropdown box
223-- | Create a dropdown box
225-- 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
224-- 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)
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)
227−dropdown k0 options = do
226+dropdownDynAttr attrs k0 options = do
228− (eRaw, _) <- elAttr' "select" ("class" =: "form-control") $ do
227+ (eRaw, _) <- elDynAttr' "select" attrs $ do
229 optionsWithDefault <- mapDyn (`Map.union` (k0 =: "")) options
228 optionsWithDefault <- mapDyn (`Map.union` (k0 =: "")) options
230 listWithKey optionsWithDefault $ \k v -> do
229 listWithKey optionsWithDefault $ \k v -> do
231 elAttr "option" ("value" =: show k <> if k == k0 then "selected" =: "selected" else mempty) $ dynText v
230 elAttr "option" ("value" =: show k <> if k == k0 then "selected" =: "selected" else mempty) $ dynText v
@@ -240,6 +239,9 @@ dropdown k0 options = do
240 dValue <- combineDyn readKey options =<< holdDyn (Just k0) eChange
239 dValue <- combineDyn readKey options =<< holdDyn (Just k0) eChange
241 return $ Dropdown dValue
240 return $ Dropdown dValue
242
241
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+
243--TODO: Get rid of Show k and Read k by indexing the possible values ourselves
245--TODO: Get rid of Show k and Read k by indexing the possible values ourselves
244dropdown' :: forall k t m. (MonadWidget t m, Eq k, Show k, Read k) => k -> NonEmpty (k, String) -> m (Dropdown t k)
246dropdown' :: forall k t m. (MonadWidget t m, Eq k, Show k, Read k) => k -> NonEmpty (k, String) -> m (Dropdown t k)
245dropdown' k0 ks = do
247dropdown' k0 ks = do