Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <label>Designations</label>
  2. <%= f.association :designation, input_html: { id: 'designation_select'},label_html: { class: 'form-control-plaintext' } %>
  3.  
  4. <label>Benefits</label>
  5. <%= f.collection_select :benefit_ids, Benefit.all,:id, :name, {}, { id: 'benefit_select',multiple: 'multiple', :class => 'form-control multiselect-all',:include_blank => "Select Benefit" } %>
  6.  
  7. <script type="text/javascript">
  8. document.addEventListener("turbolinks:load", function() {
  9.  
  10. $('#designation_select').change(function() {
  11. debugger
  12. id = $('#designation_select')[0].value;
  13. $.ajax({
  14. type: 'GET',
  15. dataType: 'json',
  16. data: {designation_id: id},
  17. url: '/benefits/benefit_by_designation',
  18. success: function(result) {
  19. debugger
  20. var el, length, options, parser, results, x;
  21. $('#benefit_select').empty();
  22. $('#benefit_select').prepend('<option value=''> Select Benefit </option>');
  23. parser = new DOMParser;
  24. el = parser.parseFromString(result, 'text/html');
  25. options = el.getElementsByTagName('option');
  26. length = options.length;
  27. x = 0;
  28. results = [];
  29. while (x < length) {
  30. $('#designation_select')[0].appendChild(options[0]);
  31. results.push(x++);
  32. }
  33. return results;
  34. }
  35. });
  36. });
  37. });
  38. </script>
  39.  
  40. def benefit_by_designation
  41. benefits = Benefit.where('designation_id = ?', params[:designation_id])
  42. render html: view_context.options_from_collection_for_select(benefits, :id, :name, {include_blank: 'Select Benefit'})
  43. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement