Hello everyone, I am currently working on Rails 3.2.13 and have implemented the following script in my view file. Whenever a user selects 'Other' as their owner type, I need the div with id=group_user_id to open and save the operation at the end. Everything was working fine when using f.radio_button.
<div class="form-group">
Owner:
<%= f.radio_button :owner_type,"Self", :id=>"self-group", :checked =>true %>
Self
<%= f.radio_button :owner_type,"Other",:id=>"other-group" %>
Others
</div>
<div id="group_user_id" class="form-group">
<span>
<%= text_field_tag "account_id", nil, :id => "autocomplete_text", :class => "form-control", :placeholder => "Account Id" %>
</span>
</div>
Javascript code
<script>
$(document).ready(function() {
$("#group_user_id").hide();
$("#self-group").prop("checked", true);
$("#other-group").click(function() {
$("#group_user_id").show();
});
});
Recently, I started using template CSS for radio buttons which caused some issues. Below is the relevant code snippets.
In this scenario, the radio button class square-green single-row is being utilized. The Rails radio button is hidden even though proper ids were provided.
<div class="row">
<div class="col-sm-2">
<div class="text-green" style="margin-top: 9px; font-size: 18px;">
Owner
</div>
</div>
<div class="col-sm-2">
<div class="icheck">
<div class="square-green single-row">
<div class="radio">
<%= f.radio_button :owner_type,"Self", :id=>"self-group", :checked =>true %>
<label>Self</label>
</div>
</div>
</div>
</div>
<div class="col-sm-2">
<div class="icheck">
<div class="square-green single-row">
<div class="radio">
<%= f.radio_button :owner_type,"Other",:id=>"other-group" %>
<label>Others </label>
</div>
</div>
</div>
</div>
</div>
I have also incorporated the following js and css files.
<%= stylesheet_link_tag "css/iCheck/skins/square/green.css" %>
<%= javascript_include_tag "js/iCheck/jquery.icheck.js", "js/icheck-init.js" %>
If you have any suggestions on how to manage radio button interactions such as clicks, checks, and other properties when utilizing template radio buttons, please share. Thank you!