Advertisement
Guest User

Untitled

a guest
May 19th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. // Define a global variable to store the selected item on selection of a checkbox
  2. var selected_values;
  3. // Trigger a function on prefill success once the repeat group is prefilled based on the salesforce selected item
  4. window.formyoula.form_fields["Contact"].on("prefill:success", function(){
  5. // Trigger the below function once the data is populated and the checkbox is selected/unselected
  6. $(document).on('change', 'input[type="checkbox"]', function(e){
  7. // If selected hide the repeat groups other than the selected one
  8. if( $(this).is(':checked') && window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value){
  9. if_checked();
  10. } else {
  11. if_not_checked();
  12. }
  13. });
  14. });
  15. // Trigger the change event on click of checkbox
  16. $(document).on('change', 'input[type="checkbox"]', function(e){
  17. // If the checkbox is selected hide the repeat groups other than the selected one
  18. if($(this).is(':checked') && window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value ){
  19. if_checked();
  20. } else {
  21. if_not_checked();
  22. }
  23. });
  24. // Trigger the below function on click of back button in the page
  25. $(document).on( "click",".back ", function() {
  26. //Checked
  27. if_checked()
  28. });
  29. // Trigger the function on clicking next
  30. $('.next').on('click', function () {
  31. // Populate the values based on the selected checbox
  32. setTimeout(function() {
  33. // Change the id's inside form_field as required
  34. formyoula.form_fields["a63f-753a-f247"].set('value', selected_values[1].value);
  35. formyoula.form_fields["0b4e-728d-7ee5"].set('value', selected_values[2].value);
  36. formyoula.form_fields["9869-2cab-d5de"].set('value', selected_values[5].value);
  37. formyoula.form_fields["b7e7-b5a7-430a"].set('value', selected_values[4].value);
  38. }, 1000);
  39. })
  40.  
  41. //Hide on add
  42. // Trigger the change event on click of checkbox
  43. $(document).on('click', '.add', function(){
  44. // If the checkbox is selected hide the repeat groups other than the selected one
  45. if( window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value ){
  46. //If checked
  47. if_checked();
  48. } else {
  49. //If not checked
  50. if_not_checked();
  51. }
  52. });
  53.  
  54. function if_checked(){
  55. // Loop through the repeat elements in the repeat group
  56. window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value.forEach(function(index, ival) {
  57. // Loop through the index, Here index consists of the values for the elements that are within the repeat group element
  58. for (var i=0; i<index.length; i++) {
  59. // If the checkbox is selected then assign the value to selected_values inorder have a copy
  60. if (index[i].type == "CheckBox" && index[i].value == true) {
  61. selected_values = index;
  62. var element_length = $('#component-7221-d2aa-1adf .existing_repeat_entry_panel').length
  63. // Loop through each repeat element using the css class and hide the particular repeat element whose checkbox aren't selected
  64. for (var j=0; j<element_length; j++) {
  65. if (j !=ival) {
  66. // Apply the css display:none if the checkbox within the repeat element isn't selected
  67. $('#component-7221-d2aa-1adf .existing_repeat_entry_panel')[j].style.display = 'none';
  68. }
  69. }
  70. }
  71. }
  72. })
  73. }
  74.  
  75. function if_not_checked() {
  76. var element_length = $('#component-7221-d2aa-1adf .existing_repeat_entry_panel').length
  77. //Show all the repeat group if deselected
  78. for (var j=0; j<element_length; j++) {
  79. // Apply the css class display:block if the selected checkbox is unselected
  80. $('#component-7221-d2aa-1adf .existing_repeat_entry_panel')[j].style.display = 'block';
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement