新的Yesod,Javascript和Web编程一般,我真的不知道从哪里开始寻找。事情就是这样:我在Yesod中写了一个小的自定义表单字段,并排显示两个多选列表,用户可以将项目从一个列表移动到另一个列表(“选择项目”)。该字段的结果是用户按下提交时右侧的项目列表。
这通常很好用,除非它没有:-):浏览器每隔一段时间就会挂起提交(POST)30秒,然后报告500内部服务器错误,抱怨缺少编码。在这种情况下,Web服务器未收到任何POST。如果我不等待这30秒,而是停止并重试(Firefox)或只是重试(Chrome),它可以工作。我有什么明显的遗失吗?
这是表格代码:
import Import
import Data.Text as T
toFromField :: [(Text, Int)] -> Field Handler [(Int)]
toFromField sis =
Field
{ fieldParse = \rawVals _ ->
case rawVals of
[] -> return $ Right Nothing
[xs] -> return $ Right $ Just $ Import.map parseInt $ Import.filter ("" /=) $ splitOn "_" xs
, fieldView = \idAttr nameAttr otherAttrs eResult isReq ->
$(widgetFile "tofrom")
, fieldEnctype = Multipart --UrlEncoded
}
mkOptions :: [(Text, Int)] -> WidgetT a IO ()
mkOptions sis = do
mapM_ (\(x, i) -> opt x i) sis
opt :: Text -> Int -> WidgetT a IO ()
opt s i = [whamlet|
<option value="#{i}">#{s}
|]
parseInt :: Text -> Int
parseInt t =
let [(x,_)] = reads (T.unpack t) :: [(Int, String)]
in x
这是朱利叶斯:
function sortSelect(selElem) {
var tmpAry = new Array();
for (var i=0;i<selElem.options.length;i++) {
tmpAry[i] = new Array();
tmpAry[i][0] = selElem.options[i].text;
tmpAry[i][1] = selElem.options[i].value;
}
tmpAry.sort();
while (selElem.options.length > 0) {
selElem.options[0] = null;
}
for (var i=0;i<tmpAry.length;i++) {
var op = new Option(tmpAry[i][0], tmpAry[i][1]);
selElem.options[i] = op;
}
return;
}
function move(fromID, toID, storeID, dir)
{
var from = document.getElementById(fromID);
var to = document.getElementById(toID);
for (var i = 0; i < from.options.length; i++)
{
if (from.options[i].selected)
{
to.options.add(new Option(from.options[i].text, from.options[i].value));
from.remove(i--);
}
}
var storeValue = "";
var rightside = "";
if (dir == 'left') { rightside=from; } else { rightside=to };
for (var i = 0; i < rightside.options.length; i++)
{
storeValue = storeValue + rightside.options[i].value + '_';
}
document.getElementById(storeID).value = storeValue;
sortSelect(to);
}
哈:
<table>
<tr>
<td rowspan="2"><select id=#{idAttr}-from name=#{nameAttr}-from multiple> ^{mkOptions sis}
<td><input type=button name="To" value=">>>"
onclick="move('#{idAttr}-from','#{idAttr}-to','#{idAttr}', 'right')">
<td rowspan="2"><select id=#{idAttr}-to name=#{nameAttr}-to multiple>
<tr>
<td><input type=button name="From" value="<<<"
onclick="move('#{idAttr}-to','#{idAttr}-from','#{idAttr}', 'left')">
<input type="hidden" id=#{idAttr} name=#{nameAttr}>
和Handler文件的一部分:
generateSel label recTime route = do
recs <- getRecs recTime
(widget, enctype) <- generateFormPost $ renderDivs
$ aopt (toFromField recs) label Nothing
defaultLayout
[whamlet|
<form method=post action=@{route} enctype=#{enctype}>
^{widget}
<input type=submit value="Los">
|]
答案 0 :(得分:1)
问题与形式无关,正如迈克尔建议的那样。 settings.yml输错了。在settings.yml中输入错误。