The code is just a simple widget. Here just i added two repeaters with a text control which i want to edit in inline. Now in the widget inline editing is working fine but it can’t saved.
But when i use one repeater only then it’s perfectly working the inline edit and save.
Now I used this add_inline_editing_attributes for inline editing. So to save the inline edit text for two repeaters what should i do?
protected function register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => esc_html__( 'Test Plugin', 'test-plugin-td' ),
'tab' => ElementorControls_Manager::TAB_CONTENT,
]
);
$repeater = new Repeater();
$repeater->add_control(
'text',
[
'label' => __( 'Business Hour', 'test-plugin-td' ),
'type' => ElementorControls_Manager::TEXT,
'label_block' => true,
'placeholder' => __( 'First Name', 'test-plugin-td' ),
'default' => __( 'First Name', 'test-plugin-td' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'business_hours',
[
'label' => __( 'Test Plugin', 'test-plugin-td' ),
'type' => ElementorControls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'text' => __( 'First Name', 'test-plugin-td' ),
],
[
'text' => __( 'Last Name', 'test-plugin-td' ),
],
],
'title_field' => '{{{ text }}}',
]
);
$this->end_controls_section();
$this->start_controls_section(
'content_2section',
[
'label' => esc_html__( 'Test Plugin', 'test-plugin-td' ),
'tab' => ElementorControls_Manager::TAB_CONTENT,
]
);
$repeskeater = new Repeater();
$repeskeater->add_control(
'text2',
[
'label' => __( 'Business Hour', 'test-plugin-td' ),
'type' => ElementorControls_Manager::TEXT,
'label_block' => true,
'placeholder' => __( 'First Name', 'test-plugin-td' ),
'default' => __( 'First Name', 'test-plugin-td' ),
'dynamic' => [
'active' => true,
],
]
);
$this->add_control(
'business_2hours',
[
'label' => __( 'Test Plugin', 'test-plugin-td' ),
'type' => ElementorControls_Manager::REPEATER,
'fields' => $repeskeater->get_controls(),
'default' => [
[
'text' => __( 'First Name', 'test-plugin-td' ),
],
[
'text' => __( 'Last Name', 'test-plugin-td' ),
],
],
'title_field' => '{{{ text2 }}}',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
echo '<ul class="test-plugin-td">';
foreach ( $settings['business_hours'] as $index => $item ) :
$text_key = $this->get_repeater_setting_key( 'text', 'business_hours', $index );
$this->add_inline_editing_attributes( $text_key );
?>
<li class="business-hour-item">
<span <?php $this->print_render_attribute_string( $text_key ); ?>>
<?php echo esc_html( $item['text'] ); ?>
</span>
</li>
<?php
endforeach;
echo '</ul>';
echo '<ul class="test-plugin-td">';
foreach ( $settings['business_2hours'] as $index => $item ) :
$text_key = $this->get_repeater_setting_key( 'text2', 'business_2hours', $index );
$this->add_inline_editing_attributes( $text_key );
?>
<li class="business-hour-item">
<span <?php $this->print_render_attribute_string( $text_key ); ?>>
<?php echo esc_html( $item['text2'] ); ?>
</span>
</li>
<?php
endforeach;
echo '</ul>';
}