Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Last active April 19, 2024 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wpmudev-sls/ad2cbe820049c5ab65f54e31c77bf614 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/ad2cbe820049c5ab65f54e31c77bf614 to your computer and use it in GitHub Desktop.
[Forminator Pro] - Show all the repeater fields based on the repeater limit
<?php
/**
* Plugin Name: [Forminator Pro] Show all the repeaters dynamically
* Description: Displays all the repeater fields based on repeater limit.
* Author: Prashant @ WPMUDEV
* Author URI: https://premium.wpmudev.org
* License: GPLv2 or later
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly.
}
add_action( 'wp_footer', 'wpmudev_dynamic_repeater_show', 9999 );
function wpmudev_dynamic_repeater_show(){
global $post;
if ( is_a( $post, 'WP_Post' ) && !has_shortcode($post->post_content, 'forminator_form') ) {
return;
}
?>
<script type="text/javascript">
jQuery( document ).ready( function($){
setTimeout(function() {
$('.forminator-custom-form').trigger('after.load.forminator');
}, 100);
$(document).on('after.load.forminator', function(e, form_id) {
if ( e.target.id == 'forminator-module-1609' ) { // Please change the form ID.
var group_options = $('#group-1 .forminator-grouped-fields').attr('data-options'); // Please change group-1 to your group field's ID.
var max_repeater = JSON.parse(group_options)['max']; // Getting max number of repeaters.
for (let i = 0; i < max_repeater; i++) {
$('.forminator-repeater-add').click();
}
}
});
});
</script>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment