@maelga I don’t remember well what was done. But I think I added the correct option as the first option in the list (see the comment line) and remove it in the loop. Hope this help.
$populate_comic_dropdown = function( $form ) {
global $post;
$parent_id = $post->post_parent;
$parent = get_post( $parent_id );
$parent_name = $parent->post_title;
$args = ['posts_per_page' => -1, 'post_type' => 'comics', 'post_parent' => '0' ];
$posts = get_posts( $args );
$items = [];
// here I added the correct option as first in the dropdown
$items[] = [ 'text' => $parent_name, 'value' => $parent_id ];
foreach ( $posts as $post ) {
if($post->ID != $parent_id)
$items[] = [ 'value' => $post->ID, 'text' => $post->post_title ];
}
foreach ( $form['fields'] as &$field ) {
if ( $field->id == 3 ) {
$field->choices = $items;
}
}
return $form;
};
add_filter( 'gform_pre_render_12', $populate_comic_dropdown );
add_filter( 'gform_pre_validation_12', $populate_comic_dropdown );
add_filter( 'gform_pre_submission_filter_12', $populate_comic_dropdown );