Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define a global variable to store the selected item on selection of a checkbox
- var selected_values;
- // Trigger a function on prefill success once the repeat group is prefilled based on the salesforce selected item
- window.formyoula.form_fields["Contact"].on("prefill:success", function(){
- // Trigger the below function once the data is populated and the checkbox is selected/unselected
- $(document).on('change', 'input[type="checkbox"]', function(e){
- // If selected hide the repeat groups other than the selected one
- if( $(this).is(':checked') && window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value){
- if_checked();
- } else {
- if_not_checked();
- }
- });
- });
- // Trigger the change event on click of checkbox
- $(document).on('change', 'input[type="checkbox"]', function(e){
- // If the checkbox is selected hide the repeat groups other than the selected one
- if($(this).is(':checked') && window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value ){
- if_checked();
- } else {
- if_not_checked();
- }
- });
- // Trigger the below function on click of back button in the page
- $(document).on( "click",".back ", function() {
- //Checked
- if_checked()
- });
- // Trigger the function on clicking next
- $('.next').on('click', function () {
- // Populate the values based on the selected checbox
- setTimeout(function() {
- // Change the id's inside form_field as required
- formyoula.form_fields["a63f-753a-f247"].set('value', selected_values[1].value);
- formyoula.form_fields["0b4e-728d-7ee5"].set('value', selected_values[2].value);
- formyoula.form_fields["9869-2cab-d5de"].set('value', selected_values[5].value);
- formyoula.form_fields["b7e7-b5a7-430a"].set('value', selected_values[4].value);
- }, 1000);
- })
- //Hide on add
- // Trigger the change event on click of checkbox
- $(document).on('click', '.add', function(){
- // If the checkbox is selected hide the repeat groups other than the selected one
- if( window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value ){
- //If checked
- if_checked();
- } else {
- //If not checked
- if_not_checked();
- }
- });
- function if_checked(){
- // Loop through the repeat elements in the repeat group
- window.formyoula.form_fields["7221-d2aa-1adf"].changed.repeat_value.forEach(function(index, ival) {
- // Loop through the index, Here index consists of the values for the elements that are within the repeat group element
- for (var i=0; i<index.length; i++) {
- // If the checkbox is selected then assign the value to selected_values inorder have a copy
- if (index[i].type == "CheckBox" && index[i].value == true) {
- selected_values = index;
- var element_length = $('#component-7221-d2aa-1adf .existing_repeat_entry_panel').length
- // Loop through each repeat element using the css class and hide the particular repeat element whose checkbox aren't selected
- for (var j=0; j<element_length; j++) {
- if (j !=ival) {
- // Apply the css display:none if the checkbox within the repeat element isn't selected
- $('#component-7221-d2aa-1adf .existing_repeat_entry_panel')[j].style.display = 'none';
- }
- }
- }
- }
- })
- }
- function if_not_checked() {
- var element_length = $('#component-7221-d2aa-1adf .existing_repeat_entry_panel').length
- //Show all the repeat group if deselected
- for (var j=0; j<element_length; j++) {
- // Apply the css class display:block if the selected checkbox is unselected
- $('#component-7221-d2aa-1adf .existing_repeat_entry_panel')[j].style.display = 'block';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement