Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <label>Designations</label>
- <%= f.association :designation, input_html: { id: 'designation_select'},label_html: { class: 'form-control-plaintext' } %>
- <label>Benefits</label>
- <%= f.collection_select :benefit_ids, Benefit.all,:id, :name, {}, { id: 'benefit_select',multiple: 'multiple', :class => 'form-control multiselect-all',:include_blank => "Select Benefit" } %>
- <script type="text/javascript">
- document.addEventListener("turbolinks:load", function() {
- $('#designation_select').change(function() {
- debugger
- id = $('#designation_select')[0].value;
- $.ajax({
- type: 'GET',
- dataType: 'json',
- data: {designation_id: id},
- url: '/benefits/benefit_by_designation',
- success: function(result) {
- debugger
- var el, length, options, parser, results, x;
- $('#benefit_select').empty();
- $('#benefit_select').prepend('<option value=''> Select Benefit </option>');
- parser = new DOMParser;
- el = parser.parseFromString(result, 'text/html');
- options = el.getElementsByTagName('option');
- length = options.length;
- x = 0;
- results = [];
- while (x < length) {
- $('#designation_select')[0].appendChild(options[0]);
- results.push(x++);
- }
- return results;
- }
- });
- });
- });
- </script>
- def benefit_by_designation
- benefits = Benefit.where('designation_id = ?', params[:designation_id])
- render html: view_context.options_from_collection_for_select(benefits, :id, :name, {include_blank: 'Select Benefit'})
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement