如何使用form_for录制此内容?
<div class="form-group">
<div class="cc-selector">
<%= f.radio_button :priorities, id: "yellow", name: "priorities", value: '1'%>
<input id="a" type="radio" name="priorities" value=1/>
<label class="priorities-cc yellow" for="a"></label>
<input id="b" type="radio" name="priorities" value=2/>
<label class="priorities-cc orange" for="b"></label>
<input id="c" type="radio" name="priorities" value=3/>
<label class="priorities-cc red" for="c"></label>
<input id="c" type="radio" name="priorities" value=4/>
<label class="priorities-cc fair" for="d"></label>
</div>
</div>
我试过了,这不行 其他字段存储在数据库中 &lt;%= f.radio_button:is_code,[a,1,b,2,c,3,d,4]%&gt;
非常感谢你的帮助!
答案 0 :(得分:0)
我看到所有其他input
代码都有integer
个值,但在f.radio_button
中,您将value
设置为'1'
,这是<%= f.radio_button :priorities, 1, id: 'yellow', class: 'priorities-cc fair', for: 'd' %>
一个字符串,您可以检查您的验证或该属性等待接收的数据类型。
尝试:
value
注意parameter
的第二个radio_button
或controller[attribute]
是它将采用的值,名称将是控制器,括号*<html>
<head>
<script src="https://www.gstatic.com/charts/loader.js" type="text/javascript"></script>
<script src="https://code.jquery.com/jquery-3.0.0.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/2014.02/jquery.SPServices.min.js" type="text/javascript"></script>
<script language="javascript">
var returnedItems = null;
function loadGoogleLibAndDraw(){
google.charts.load('current', {'packages':['bar','line']});
google.charts.setOnLoadCallback(visualizeData);
}
function visualizeData() {
var context = new SP.ClientContext();
var list = context.get_web().get_lists().getByTitle(document.getElementById('customListName').value);
var caml = new SP.CamlQuery();
caml.set_viewXml("<View></View>");
returnedItems = list.getItems(caml);
context.load(returnedItems);
context.executeQueryAsync(onSucceededCallback, onFailedCallback);
}
function onSucceededCallback(sender, args) {
var data = new google.visualization.DataTable();
data.addColumn('string', 'Part No');
data.addColumn('number', 'Volume');
var enumerator = returnedItems.getEnumerator();
var markup = '';
while (enumerator.moveNext()) {
var row = [];
var listItem = enumerator.get_current();
row.push(listItem.get_item('Part_x0020_No'));
row.push(listItem.get_item('Volume'));
data.addRow(row);
}
var options = {
chart: {
title: 'KPIs',
},
bars: 'vertical'
};
var barChart = new google.charts.Bar(document.getElementById('BarChart'));
barChart.draw(data, options);
var lineChart = new google.charts.Line(document.getElementById('LineChart'));
lineChart.draw(data, options);
}
function onFailedCallback(sender, args) {
var markup = '<p>The request failed: <br>';
markup += 'Message: ' + args.get_message() + '<br>';
displayDiv.innerHTML = markup;
}
</script>
</head>
<body onload="loadGoogleLibAndDraw()">
<form name="metricsform" id="metricsform">
<input id="customListName" name="customListName" value="Projects" type="hidden"/>
</form>
<div>
<div id="displayDiv"></div>
<div id="BarChart" style="width: 300px; height: 200px;"></div>
<div id="LineChart" style="width: 300px; height: 200px;"></div>
</div>
</body>
</html>*
上的属性。