【问题标题】:Bootstrap radio buttons in Yesod: how to get value?Yesod 中的 Bootstrap 单选按钮:如何获得价值?
【发布时间】:2015-04-21 21:15:39
【问题描述】:

我尝试从 Yesod 中的 Bootstrap 值获取单选按钮的值。所以这是我的内联收音机:

<form .form-horizontal
    ...
    <label .radio-inline>
        <input type=radio
               name=gender
               checked>_{MsgMale}
    <label .radio-inline>
        <input type=radio
               name=gender>_{MsgFemale}

但我不明白如何获得gender 的值。我试试看:

data NewPatient = NewPatient { lastName       
                             , firstName :: Text
                             , gender    :: Bool
                             } deriving Show

...

newPatient <- runInputPost $ 
              NewPatient <$> ireq textField "patientLastName"
                         <*> ireq textField "patientFirstName"
                         <*> ireq boolField "patientGender"

gender 始终是True

我尝试将value 属性用于input,但在这种情况下我收到错误Invalid boolean

我在docs 中读过这篇文章:

If this field is required, the first radio button is labeled "Yes" and the second "No". 

但我不明白。在这种情况下,“标记”是什么意思?

请帮帮我。

【问题讨论】:

  • labeled 的意思是“在单选按钮旁边有一个小的用户描述”
  • 好的,但是如何提取男性/女性按钮的值?
  • 我认为对性别使用布尔值有点奇怪。我可能会将selectFieldListradioFieldListdata Gender = Male | Female 一起使用。

标签: twitter-bootstrap radio-button yesod


【解决方案1】:

我找到了解决方案:

<form .form-horizontal
    ...
    <label .radio-inline>
        <input type=radio
               name=gender
               value=on                 <<< exactly `on` 
               checked>_{MsgMale}
    <label .radio-inline>
        <input type=radio
               value=no                 <<< exactly `no`
               name=gender>_{MsgFemale}

在这种情况下,如果用户检查了第一个按钮(男性),我有 True,如果他检查了第二个按钮(女性),我有 False

【讨论】:

    猜你喜欢
    • 2012-11-12
    • 2011-01-01
    • 2020-07-06
    • 1970-01-01
    • 2017-10-25
    • 1970-01-01
    • 2018-06-18
    • 1970-01-01
    相关资源
    最近更新 更多