This commit is contained in:
2021-10-08 16:22:44 +03:00
parent d6ddca4532
commit cf1405bef6
8 changed files with 62 additions and 47 deletions
+17 -14
View File
@@ -3,6 +3,9 @@
/**
* @var array $arParams
*/
use Wt\Core\Templater\Tools as TemplaterTools;
use Wt\Core\Tools;
use \Wt\Core\Type;
$arParamsDefault = [
@@ -36,7 +39,7 @@ $optionDefault = [
if(!isset($arParams['AUTO_SELECT'])) {
$arParams['AUTO_SELECT'] = $arParamsDefault['AUTO_SELECT'];
}
$arParams['AUTO_SELECT'] = \Bx\Kit\Tools::isTrue($arParams['AUTO_SELECT']);
$arParams['AUTO_SELECT'] = Tools::isTrue($arParams['AUTO_SELECT']);
if(!isset($arParams['OPTIONS_VALUE_KEY'])) {
$arParams['OPTIONS_VALUE_KEY'] = $arParamsDefault['OPTIONS_VALUE_KEY'];
@@ -47,22 +50,22 @@ if(!isset($arParams['OPTIONS_TEXT_KEY'])) {
$arParams['OPTIONS'] = (array)$arParams['OPTIONS'];
$arrowInLabel = \Bx\Kit\Tools::isTrue($arParams['ARROW_IN_LABEL']);
$arrowInLabel = Tools::isTrue($arParams['ARROW_IN_LABEL']);
if(!isset($arParams['CHECK_DIRTY'])) {
$arParams['CHECK_DIRTY'] = $arParamsDefault['CHECK_DIRTY'];
}
$checkDirty = \Bx\Kit\Tools::isTrue($arParams['CHECK_DIRTY']);
$checkDirty = Tools::isTrue($arParams['CHECK_DIRTY']);
$optionSelectedArray = [];
$hidden = \Bx\Kit\Tools::isTrue($arParams['HIDDEN']) || ($arParams['TYPE'] == 'hidden');
$multiple = \Bx\Kit\Tools::isTrue($arParams['MULTIPLE']);
$hidden = Tools::isTrue($arParams['HIDDEN']) || ($arParams['TYPE'] == 'hidden');
$multiple = Tools::isTrue($arParams['MULTIPLE']);
$optionsHtml = '';
if($arParams['OPTIONS']) {
if(strlen($arParams['SELECTED'])) {
foreach ($arParams['OPTIONS'] as $option) {
if(isset($option['VISIBLE']) && !\Bx\Kit\Tools::isTrue($option['VISIBLE'])) continue;
if(isset($option['VISIBLE']) && !Tools::isTrue($option['VISIBLE'])) continue;
if($arParams['SELECTED'] == Type\Arr::get($option, $arParams['OPTIONS_VALUE_KEY'])) {
$optionSelectedArray = $option;
break;
@@ -73,8 +76,8 @@ if($arParams['OPTIONS']) {
if($arParams['AUTO_SELECT']) {
if(!$optionSelectedArray) {
foreach ($arParams['OPTIONS'] as $option) {
if(isset($option['VISIBLE']) && !\Bx\Kit\Tools::isTrue($option['VISIBLE'])) continue;
if(\Bx\Kit\Tools::isTrue($option['SELECTED'])) {
if(isset($option['VISIBLE']) && !Tools::isTrue($option['VISIBLE'])) continue;
if(Tools::isTrue($option['SELECTED'])) {
$optionSelectedArray = $option;
break;
}
@@ -88,12 +91,12 @@ if($arParams['OPTIONS']) {
}
$optionsCount = 0;
foreach ($arParams['OPTIONS'] as $option) {
if(isset($option['VISIBLE']) && !\Bx\Kit\Tools::isTrue($option['VISIBLE'])) continue;
if(isset($option['VISIBLE']) && !Tools::isTrue($option['VISIBLE'])) continue;
$isSelected = (Type\Arr::get($optionSelectedArray, $arParams['OPTIONS_VALUE_KEY']) == Type\Arr::get($option, $arParams['OPTIONS_VALUE_KEY']));
$isDisabled = \Bx\Kit\Tools::isTrue($option['DISABLED']) || \Bx\Kit\Tools::isTrue($option['RESTRICTED']);
$isDisabled = Tools::isTrue($option['DISABLED']) || Tools::isTrue($option['RESTRICTED']);
$optionsCount++;
$optionsHtml .= ' <option value="'.Type\Arr::get($option, $arParams['OPTIONS_VALUE_KEY']).'" '. \Bx\Kit\Node\Lib::getAttrByArray($option['ATTR']) .
$optionsHtml .= ' <option value="'.Type\Arr::get($option, $arParams['OPTIONS_VALUE_KEY']).'" '. TemplaterTools::getAttrByArray($option['ATTR']) .
($isSelected?' selected':'').''.
($isDisabled?' disabled':'').'>'.Type\Arr::get($option, $arParams['OPTIONS_TEXT_KEY']).'</option>';
}
@@ -105,9 +108,9 @@ foreach ($arParams['OPTIONS'] as $option) {
name="<?=$arParams['NAME']?>"
<?if($arParams['ID']){?>id="<?=$arParams['ID']?>"<?}?>
<?if($multiple){?> multiple<?}?>
<?if($arParams['ONCHANGE']){?> onchange="<?=\Bx\Kit\Lib\Type\Str::safeHtmlAttr($arParams['ONCHANGE'])?>"<?}?>
<?if($arParams['ONCHANGE']){?> onchange="<?=TemplaterTools::safeHtmlAttr($arParams['ONCHANGE'])?>"<?}?>
class="kit-field__input <?=$arParams['CLASS']?> <?=$arParams['ADD_CLASS']?>"
<?=\Bx\Kit\Node\Lib::getAttrByArray($arParams['ATTR'])?>
<?=TemplaterTools::getAttrByArray($arParams['ATTR'])?>
<?if($arParams['PLACEHOLDER']){?>data-placeholder="<?=$arParams['PLACEHOLDER']?>"<?}?>
><?echo $optionsHtml?:$arParams['OPTIONS_HTML']; ?></select>
<?
@@ -116,7 +119,7 @@ foreach ($arParams['OPTIONS'] as $option) {
}?>
<?if(!$arrowInLabel){?><span class="kit-field__arrow"><?=app()->service()->templater()->get('kit:svg/chevronAnimate')?></span><?}?>
<span class="kit-field__display"><?=Type\Arr::get($optionSelectedArray, $arParams['OPTIONS_TEXT_KEY'])?:$arParams['PLACEHOLDER']?></span>
<span class="kit-field__label"><?=$arParams['LABEL']?:$arParams['NAME']?:''?><?if($arrowInLabel){?><span class="kit-field__arrow"><?=\Bx\Kit\Template::get('svg/chevronAnimate')?></span><?}?></span>
<span class="kit-field__label"><?=$arParams['LABEL']?:$arParams['NAME']?:''?><?if($arrowInLabel){?><span class="kit-field__arrow"><?=app()->service()->templater()->get('svg/chevronAnimate')?></span><?}?></span>
<span class="kit-field__error"></span>
<span class="kit-field__hr"></span>
<?if($arParams['AREA_LEFT']){?><div class="kit-field__area-left"><?=$arParams['AREA_LEFT']?></div><?}?>