A
A
Andrey Pogorelov2019-02-15 00:00:00
1C-Bitrix
Andrey Pogorelov, 2019-02-15 00:00:00

How to make a custom property with multiple fields in Bitrix?

OnIBlockPropertyBuildList has a GetPropertyFieldHtmlMulty method . But I don't quite understand how to save multiple fields. It turns out with only one:

AddEventHandler("iblock", "OnIBlockPropertyBuildList", array("CIBlockPropertyCustom", "GetUserTypeDescription"));
class CIBlockPropertyCustom
{
    public function GetUserTypeDescription()
    {
        return array(
            "PROPERTY_TYPE"        => "F",
            "USER_TYPE"            => "SERVICE",
            "DESCRIPTION"          => "Фотогалерея",
            "GetPropertyFieldHtml" => array("CIBlockPropertyCustom", "GetPropertyFieldHtml"),
        );
    }

    public static function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
    {
        return '<input type="text" name="'.$strHTMLControlName["VALUE"].'" value="'.$value['VALUE'].'">';
    }
}

As a result, I need to save two fields: a file and a text field
5c65d6b851d6c418262379.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ilya, 2019-02-15
@jasper-blondin

File is a number. The second field is a string.
To store 2 separate values ​​in one database field, you need to develop your own data serialization method.
To modify values ​​before saving to the database and after reading from the database, additionally describe the ConvertToDB and ConvertFromDB methods, respectively.
PS
One more option: write the text part of the property value as DESCRIPTION to the saved file (when you execute the CFile::Save method).

A
Alexander Zemlyanoy, 2019-02-15
@Galamoon

I have not worked with this functionality for a long time, it should be the same as with one, only in the second parameter there will be not one value, but an array of values. js for the "Add" button also seems to need to be written by yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question