Hello!
I created a field group Repeater in the ACF plugin with the name hp_listing_master.
And the fields in this group Gallery with the name hp_listing_galereya and Text area with the name hp_listing_opisanie.
In the Location rules, I specified the Record type - equals - Advertisement. As a result, this field group is displayed in the admin panel, when adding a new advertisement and editing an advertisement.
But this field group is not displayed when adding a new advertisement and editing an advertisement on the frontend.
Tell me how to fix this error?
Thank you!
Hi,
Our Forms API is not based on ACF and unfortunately there are no equal field types for ACF’s Gallery and Repeater. We have a Repeater field type, but in the current version it requires configuration via a code snippet, I can provide a sample snippet if needed.
Hi, ihor
Yes, please tell me what I should start from.
Provide a code snippet example. And any other hint so I can implement this.
Thanks!
Please try using this sample code snippet A working sample of a repeater? - #4 by ihor It adds the Repeater field to both back-end and front-end forms, handles validation and saving values.
Thanks, ihor. I’ve seen this code before and applied it to text fields.
But I need to add a “Repeater” field to forms with images.
Did it occur to you to replace text by image (or images) ?
I tried, but the image upload field doesn’t show up.
It doesn’t work.
add_filter('hivepress/v1/models/listing/attributes', function($attributes) {
$attributes['masters'] = [
'editable' => true,
'edit_field' => [
'type' => 'repeater',
'label' => 'Мастера',
'_order' => 1000,
'button_caption' => '<span>Добавить мастера</span>',
'fields' => [
'masters__images' => [
'type' => 'attachment',
'label' => 'Изображение услуги',
'multiple' => true,
'max_files' => 10,
'formats' => [ 'jpg', 'jpeg', 'png' ],
'_model' => 'attachment',
],
'masters_price' => [
'type' => 'number',
'label' => 'Стоимость',
'placeholder' => 'Стоимость',
'min_value' => 0,
'suffix' => '₽',
],
'masters_description' => [
'type' => 'textarea',
'label' => 'Описание',
'placeholder' => 'Краткое описание (максимум 50 символов)',
'max_length' => 50, // Жесткое ограничение символов
'rows' => 3, // Высота поля ввода
],
],
],
];
return $attributes;
});
So the image upload field is added, but when you upload images, they are not saved. And the repeater does not work
add_filter('hivepress/v1/models/listing/attributes', function($attributes) {
$attributes['masters'] = [
'editable' => true,
'edit_field' => [
'type' => 'repeater',
'label' => 'Мастера',
'_order' => 1000,
'button_caption' => '<span>Добавить мастера</span>',
'fields' => [
'masters__images' => [
'type' => 'attachment_upload',
'label' => 'Изображение услуги',
'multiple' => true,
'max_files' => 10,
'formats' => [ 'jpg', 'jpeg', 'png' ],
'_model' => 'attachment',
],
'masters_price' => [
'type' => 'number',
'label' => 'Стоимость',
'placeholder' => 'Стоимость',
'min_value' => 0,
'suffix' => '₽',
],
'masters_description' => [
'type' => 'textarea',
'label' => 'Описание',
'placeholder' => 'Краткое описание (максимум 50 символов)',
'max_length' => 50, // Жесткое ограничение символов
'rows' => 3, // Высота поля ввода
],
],
],
];
return $attributes;
});
So the image upload field is not displayed
add_filter('hivepress/v1/models/listing/attributes', function($attributes) {
$attributes['masters'] = [
'editable' => true,
'edit_field' => [
'type' => 'repeater',
'label' => 'Мастера',
'_order' => 1000,
'button_caption' => '<span>Добавить мастера</span>',
'fields' => [
'masters__images' => [
'type' => 'image',
'label' => 'Изображение услуги',
'formats' => [ 'jpg', 'jpeg', 'png' ],
],
'masters_price' => [
'type' => 'number',
'label' => 'Стоимость',
'placeholder' => 'Стоимость',
'min_value' => 0,
'suffix' => '₽',
],
'masters_description' => [
'type' => 'textarea',
'label' => 'Описание',
'placeholder' => 'Краткое описание (максимум 50 символов)',
'max_length' => 50, // Жесткое ограничение символов
'rows' => 3, // Высота поля ввода
],
],
],
];
return $attributes;
});
Please correct me if I am wrong and there are errors in my code.
Unfortunately there’s no easy way to nest the Attachment field inside the Repeater field in the current framework version, this would require a custom implementation. You can try using the attachment field without the “multiple” flag, but if I remember correctly the field type itself is not supported for nesting in repeatable elements.