Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用javascript和rails添加依赖输入的客户端验证?_Javascript_Jquery_Ruby On Rails_Validation - Fatal编程技术网

如何使用javascript和rails添加依赖输入的客户端验证?

如何使用javascript和rails添加依赖输入的客户端验证?,javascript,jquery,ruby-on-rails,validation,Javascript,Jquery,Ruby On Rails,Validation,我猜这是一个非常常见的过程,但我很难找到解决方案,因为我不知道该如何表达这个问题。基本上,我需要为依赖于另一个输入选择的下拉列表添加验证检查,但后一个输入是另一种形式的。因此,我认为这意味着我需要对数据库进行验证。我正试图找出一个好的方法来做到这一点,并将非常感谢您的建议 为了提供更多的上下文,这两个输入是相互依赖的。第一个是空气处理器类型列表。这是实际输入: <div class="field heating_type"> <%= f.label :heating_air

我猜这是一个非常常见的过程,但我很难找到解决方案,因为我不知道该如何表达这个问题。基本上,我需要为依赖于另一个输入选择的下拉列表添加验证检查,但后一个输入是另一种形式的。因此,我认为这意味着我需要对数据库进行验证。我正试图找出一个好的方法来做到这一点,并将非常感谢您的建议

为了提供更多的上下文,这两个输入是相互依赖的。第一个是空气处理器类型列表。这是实际输入:

<div class="field heating_type">
  <%= f.label :heating_air_handler_type_id, "Heating Type", :class => "required" %>
  <%= collection_select(:air_handler, :heating_air_handler_type_id, AirHandlerType.where("for_heating = ?", true).order("sort_order"), :id, :display_name, {}) %>
</div>

“必需”%>
另一个输入是设备类型列表:

<div class="field plant_type">
  <%= f.label :plant_type_id, "Plant Type", :class => "required" %>
  <%= collection_select(:plant, :plant_type_id, PlantType.order("sort_order"), :id, :display_name, {}, { :class => "required" }) %>
</div>

“必需”%>
“必需”})%%>
基本上,当用户选择“热泵”的空气处理器加热类型时,我必须确保设备类型不是冷却器。我还需要它以相反的方向工作,因此如果用户选择冷水机,就会警告用户它与热泵选择不兼容


如果我没有提供足够的信息,请让我知道,我会填写更多的细节

使用带有onchange事件的javascript/jquery绑定加热类型选择框。 在该M函数中,您可以更改其他列表中的值。添加或删除,或只是隐藏或禁用。但是,您希望调整第二个选择列表