我有一个带滑动条的表单,默认值为默认值(value
下的代码)。当我单击提交按钮时,它会正确计算结果或手动更改默认值。当手动更改默认值时,它会再次刷新页面并将值设置为默认值。
表单是这个表单,我在部分视图中用于订购目的。
<%= form_tag() do %>
<h2>J <a id="dialog-1" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<div id="slider-jahresverbrauch"></div>
<%= text_field_tag "user_entry_module1", params["user_entry_module1"] || "", id: "amount-jahresverbrauch", disable: true, class: "amount", size: 2 %>
<span>kWh</span>
<h2>PV <a id="dialog-2" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<div id="slider-pvgrosse"></div>
<%= text_field_tag "user_entry_module2", params["user_entry_module2"] || "", id: "amount-pvgrosse", class: "amount", size: 2 %>
<span>kWp</span>
<h2>S <a id="dialog-3" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<div id="slider-strompreis"></div>
<%= text_field_tag "user_entry_module3", params["user_entry_module3"] || "", id: "amount-strompreis", class: "amount", size: 2 %>
<span>cent/kWh</span>
<h2>St <a id="dialog-4" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<div id="slider-strompreissteigerung"></div>
<%= text_field_tag "user_entry_module4", params["user_entry_module4"] || "", id: "amount-strompreissteigerung", class: "amount", size: 2 %>
<span>%</span>
<h2>E <a id="dialog-5" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<div id="slider-ertrag"></div>
<%= text_field_tag "user_entry_module5", params["user_entry_module5"] || "", id: "amount-ertrag", class: "amount", size: 2 %>
<span>kWh/kWp</span>
<h2>D <a id="dialog-6" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<div id="slider-degression"></div>
<%= text_field_tag "user_entry_module6", params["user_entry_module6"] || "", id: "amount-degression", class: "amount", size: 2 %>
<span>pro Jahr %</span>
<h2 class="text-input">P <a id="dialog-7" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<%= text_field_tag "user_entry_module7", params["user_entry_module7"] || "", value: "1600", id: "", class: "text-input last-input", size: 2 %>
<span class="text-input anlagepreis-unit" >pro kWp</span>
<h2 class="text-input">E <a id="dialog-8" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<%= text_field_tag "user_entry_module8", params["user_entry_module8"] || "", value: "12", id: "", class: "text-input last-input", size: 2 %>
<span class="text-input anlagepreis-unit" >cent/kWh</span>
<h2 class="">? <a id="dialog-9" href="#" ><i class="fa fa-info-circle"></i></a></h2>
<%= text_field_tag "user_entry_module9", params["user_entry_module9"] || "", value: "ja", id: "", class: "", size: 2 %>
<%= submit_tag "Berechnen", class: "send_button_1" %>
<% end %>
我有application.html.erb
和front_end.html.erb
次观看。
在front_end.html.erb
中,结构或多或少是这样的:
<%= render "partials/form" %>
<script>
$(function() {
/Jahresstromverbrauch
$( "#slider-jahresverbrauch" ).slider({
value:3300,
min: 2000,
max: 8800,
step: 100,
slide: function( event, ui ) {
$( "#amount-jahresverbrauch" ).val(ui.value);
}
});
$( "#amount-jahresverbrauch" ).val($( "#slider-jahresverbrauch" ).slider( "value" ));
// in this way I define the other slide bars.
// Ajax call to code1
// Ajax call to code 2 (depends on the results from code1)
// Plotting with highcharts
});
</script>
路线:
Prefix Verb URI Pattern Controller#Action
api_v2_energycalcsb_get_values POST /api/v2/energycalcsb/get_values(.:format) api/v2/energycalcsb#get_values
api_v3_financecalc_get_eco POST /api/v3/financecalc/get_eco(.:format) api/v3/financecalc#get_eco
calculation_front_end POST /calculation/front_end(.:format) calculation#front_end
root GET / calculation#front_end
问题:如何在点击提交按钮后更新维护这些值的值后避免这种情况?我注意到再次调用点击地址时(加载application.html和front_end.html .erb)
更新:我正在尝试避免提交时刷新页面。 示例:假设我有一个带有默认值(3300)的滑动条。 (在我的应用程序中,所有的滑动条都已初始化,因此只需单击提交按钮,它就会计算出正确的一切)。当切片所有滑动条(在这个例子中让我们说5000)时,它会显示正确的结果但是由于刷新,滑动条再次设置为默认值(3300)。