S
S
sitnikovroman19942019-08-21 12:25:21
1C-Bitrix
sitnikovroman1994, 2019-08-21 12:25:21

How to create a custom custom property of the multiple list type in 1c bitrix?

Good afternoon. There is a task - to add a custom custom property of the list type to the infoblock, with the possibility of multiple selection.
The usual list property will not work, since the values ​​​​of this list will
constantly change and must be pulled from the database before displaying the list in the admin panel.
I tried to do it by analogy as here stackoverflow.com
I got the following code in init.php

/*--------- вывод поля свойства на странице редактирования ---------*/
    public function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
    {

        /** Массив объявлен хардкодом для примера, значения берутся из базы */
        $arElements = [
            'test1',
            'test2',
            'test3',
            'test4',
            'test5',
            'test6',
            'test7',
            'test8',
        ];

        $sReturn = '';
        $sReturn = '<select multiple size="6" name="PROP[' . $arProperty['ID'] . '][]">';
        foreach($arElements as $key => $value) {
            $sReturn .= '<option value="'.$key.'"';
            if($arProperty == $key) {
                $sReturn .= ' selected="selected"';
            }
            $sReturn .= '>'.$value.'</option>';
        }
        $sReturn .= '</select>';
        return $sReturn;
    }

    public static function ConvertToDB($arProperty, $arValue)
    {
            return $arValue;

    }

    public static function ConvertFromDB($arProperty, $arValue)
    {
            return $arValue;
    }
}

I created the property, everything is displayed correctly on the element editing page.
Here is the HTML code of the property
/*--------- вывод поля свойства на странице редактирования ---------*/
    public function GetPropertyFieldHtml($arProperty, $value, $strHTMLControlName)
    {

        /** Массив объявлен хардкодом для примера, значения берутся из базы */
        $arElements = [
            'test1',
            'test2',
            'test3',
            'test4',
            'test5',
            'test6',
            'test7',
            'test8',
        ];

        $sReturn = '';
        $sReturn = '<select multiple size="6" name="PROP[' . $arProperty['ID'] . '][]">';
        foreach($arElements as $key => $value) {
            $sReturn .= '<option value="'.$key.'"';
            if($arProperty == $key) {
                $sReturn .= ' selected="selected"';
            }
            $sReturn .= '>'.$value.'</option>';
        }
        $sReturn .= '</select>';
        return $sReturn;
    }

    public static function ConvertToDB($arProperty, $arValue)
    {
            return $arValue;

    }

    public static function ConvertFromDB($arProperty, $arValue)
    {
            return $arValue;
    }
}

But for some reason the data is not saved. After pressing the save button, a redirect to the list of all elements occurs, as usual, upon successful saving. But the value doesn't change.
How can this situation be corrected? Options to solve the problem in a different way or demolish Bitrix unfortunately do not fit, since it does not depend on me

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sitnikovroman1994, 2019-08-22
@sitnikovroman1994

Solved the problem with a crutch

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question