如何在单选按钮标签内插入 html(在 Yesod 中)

发布于 2025-01-05 20:47:35 字数 2733 浏览 2 评论 0原文

我尝试将 html 渲染为 radiofieldList 的标签,但出现了以下错误。

Handler/Manager.hs:91:32:
No instance for (RenderMessage Scheduler (Handler RepHtml))
  arising from a use of `radioFieldList'
Possible fix:
  add an instance declaration for
  (RenderMessage Scheduler (Handler RepHtml))
In the first argument of `mreq', namely `(radioFieldList bPairs)'
In a stmt of a 'do' block:
  (jobRes, jobView) <- mreq
                         (radioFieldList bPairs) "Scheduled Jobs" Nothing
In the expression:
  do { let bPairs = buttonPairs kjPairs
           statusPairs
             = map (pack . show &&& id) $ ([minBound .. maxBound] :: [Status            ]);
       (jobRes, jobView) <- mreq
                              (radioFieldList bPairs) "Scheduled Jobs" Nothing;
       (noteRes, noteView) <- mreq textareaField " Notes " Nothing;
       (statusRes, statusView) <- mreq
                                    (selectFieldList statusPairs) " Status " Nothing;
       .... }

因此,考虑到下面的代码,为 (RenderMessage Scheduler (Handler RepHtml)) 创建一个实例是否有意义?

statusForm :: RForm CapturedData
statusForm kjPairs extra = do
let bPairs = buttonPairs kjPairs
    statusPairs = map (pack . show &&& id) $
                  ([minBound .. maxBound] :: [Status])
(jobRes ,jobView) <- mreq (radioFieldList bPairs) "Scheduled Jobs" Nothing
(noteRes, noteView) <- mreq textareaField " Notes " Nothing
(statusRes, statusView) <- mreq (selectFieldList statusPairs) " Status " Nothing    -- as of 0.9.4.x it is just best to explicitly type widgetFile
let widget = toWidget ($(widgetFile "status") :: Widget)
return (CapturedData <$> jobRes <*> statusRes  <*> noteRes
       , widget)

buttonPairs :: [KeyJobPair] -> [(Handler RepHtml,KeyJobPair)]
buttonPairs kjList = sort $ map buttonPairs' kjList
  where buttonPairs' :: KeyJobPair -> (Handler RepHtml,KeyJobPair)
    buttonPairs' (KeyJobPair ((Key key), JobData (Firmware product)
                                           (Version version)
                                           (StartDate sDate)
                                            status)) =
      let (Right jid) = fromPersistValue key :: Either Text Int64
      in (hamletToRepHtml [hamlet|<a href=@{RootR}(" Job Id " ++ (show jid))>|]
         ,KeyJobPair (Key key, JobData (Firmware product)
                                       (Version version)
                                       (StartDate sDate)
                                       status))

我想到,真正的答案是创建一个接受 的自定义字段>(HTML,a),而不是所需的 (msg,a) radioFieldList 想要的。我希望只为 RenderMessage 创建一个实例就可以工作。

My attempt to render html as a label for a radiofieldList has yielded the following error.

Handler/Manager.hs:91:32:
No instance for (RenderMessage Scheduler (Handler RepHtml))
  arising from a use of `radioFieldList'
Possible fix:
  add an instance declaration for
  (RenderMessage Scheduler (Handler RepHtml))
In the first argument of `mreq', namely `(radioFieldList bPairs)'
In a stmt of a 'do' block:
  (jobRes, jobView) <- mreq
                         (radioFieldList bPairs) "Scheduled Jobs" Nothing
In the expression:
  do { let bPairs = buttonPairs kjPairs
           statusPairs
             = map (pack . show &&& id) $ ([minBound .. maxBound] :: [Status            ]);
       (jobRes, jobView) <- mreq
                              (radioFieldList bPairs) "Scheduled Jobs" Nothing;
       (noteRes, noteView) <- mreq textareaField " Notes " Nothing;
       (statusRes, statusView) <- mreq
                                    (selectFieldList statusPairs) " Status " Nothing;
       .... }

So, given the code below, does it make sense to create an instance for (RenderMessage Scheduler (Handler RepHtml))

statusForm :: RForm CapturedData
statusForm kjPairs extra = do
let bPairs = buttonPairs kjPairs
    statusPairs = map (pack . show &&& id) $
                  ([minBound .. maxBound] :: [Status])
(jobRes ,jobView) <- mreq (radioFieldList bPairs) "Scheduled Jobs" Nothing
(noteRes, noteView) <- mreq textareaField " Notes " Nothing
(statusRes, statusView) <- mreq (selectFieldList statusPairs) " Status " Nothing    -- as of 0.9.4.x it is just best to explicitly type widgetFile
let widget = toWidget ($(widgetFile "status") :: Widget)
return (CapturedData <
gt; jobRes <*> statusRes  <*> noteRes
       , widget)

buttonPairs :: [KeyJobPair] -> [(Handler RepHtml,KeyJobPair)]
buttonPairs kjList = sort $ map buttonPairs' kjList
  where buttonPairs' :: KeyJobPair -> (Handler RepHtml,KeyJobPair)
    buttonPairs' (KeyJobPair ((Key key), JobData (Firmware product)
                                           (Version version)
                                           (StartDate sDate)
                                            status)) =
      let (Right jid) = fromPersistValue key :: Either Text Int64
      in (hamletToRepHtml [hamlet|<a href=@{RootR}(" Job Id " ++ (show jid))>|]
         ,KeyJobPair (Key key, JobData (Firmware product)
                                       (Version version)
                                       (StartDate sDate)
                                       status))

It occurred to me, the true answer is to create a custom Field that will accept (HTML,a), as opposed to the required (msg,a) radioFieldList wants. I'm hoping that just creating an instance for RenderMessage will work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟沫凡尘 2025-01-12 20:47:35

您可能不需要在那里调用 hamletToRepHtml,为什么不从 Text.Hamlet 调用 renderHtml 呢?

我没有在这台机器上安装 yesod (所以我无法验证),但这应该会为您指明正确的方向。我假设您不希望它成为一个小部件,并且您只想呈现它。

You probably don't need to call hamletToRepHtml there, why not renderHtml from Text.Hamlet?

I don't have yesod installed on this machine (so I can't verify), but that should point you in the right direction. I'm assuming you don't want that to be a widget, and that you just want it rendered.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文