Answer the question
In order to leave comments, you need to log in
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;
}
}
/*--------- вывод поля свойства на странице редактирования ---------*/
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;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question