← All changes
|
includes/Frontend/Form/View/Theme/Fields/CheckBoxField.php
+92
-71
2.10.0
→
3.3.1
View file →
| @@ -22,16 +22,16 @@ | ||
| 22 | 22 | $checkBoxOptions = ''; |
| 23 | 23 | $bfFrontendFormIds = FrontendHelpers::$bfFrontendFormIds; |
| 24 | 24 | $contentCount = count($bfFrontendFormIds); |
| 25 | 25 | |
| 26 | - if (property_exists($field, 'opt') && count($field->opt) > 0) { | |
| 27 | - if (!empty($field->val) && false !== strpos($field->val, BITFORMS_BF_SEPARATOR)) { | |
| 26 | + if (is_object($field) && property_exists($field, 'opt') && is_countable($field->opt) && count($field->opt) > 0) { | |
| 27 | + if (isset($field->val) && false !== strpos($field->val, BITFORMS_BF_SEPARATOR)) { | |
| 28 | 28 | $defaultValues = explode(BITFORMS_BF_SEPARATOR, $field->val); |
| 29 | 29 | } else { |
| 30 | - $defaultValues = !empty($field->val) ? explode(',', $field->val) : []; | |
| 30 | + $defaultValues = isset($field->val) ? explode(',', $field->val) : []; | |
| 31 | 31 | } |
| 32 | 32 | foreach ($field->opt as $key => $opt) { |
| 33 | - $value = !empty($opt->val) ? $opt->val : $opt->lbl; | |
| 33 | + $value = isset($opt->val) ? $opt->val : $opt->lbl; | |
| 34 | 34 | $check = ''; |
| 35 | 35 | $req = ''; |
| 36 | 36 | $disabled = ''; |
| 37 | 37 | $href = htmlentities("#$rowID-ck-svg"); |
| @@ -46,121 +46,142 @@ | ||
| 46 | 46 | $req = 'required'; |
| 47 | 47 | } |
| 48 | 48 | if ($fieldHelpers->property_exists_nested($field, 'valid->disabled', true) |
| 49 | 49 | || $fieldHelpers->property_exists_nested($opt, 'disabled', true)) { |
| 50 | - $disabled = "disabled='disabled'"; | |
| 50 | + $disabled = 'disabled'; | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - $checkBoxOptions .= <<<CHECKBOXOPTIONS | |
| 53 | + if (isset($field->mx) && !empty($field->valid->disableOnMax) && !$check && ((int) $field->mx <= count($defaultValues))) { | |
| 54 | + $disabled = 'disabled'; | |
| 55 | + } | |
| 56 | + | |
| 57 | + $checkBoxOptions .= ' | |
| 54 | 58 | <div |
| 55 | - {$fieldHelpers->getCustomAttributes('cw')} | |
| 56 | - class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}" | |
| 59 | + ' . $fieldHelpers->getCustomAttributes('cw') . ' | |
| 60 | + class="' . $fieldHelpers->getAtomicCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '" | |
| 57 | 61 | > |
| 58 | 62 | <input |
| 59 | - id="{$rowID}-{$contentCount}-chk-{$key}" | |
| 63 | + id="' . $rowID . '-' . $contentCount . '-chk-' . $key . '" | |
| 60 | 64 | type="checkbox" |
| 61 | - class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}" | |
| 62 | - {$disabled} | |
| 63 | - value="{$value}" | |
| 64 | - {$check} | |
| 65 | - {$req} | |
| 66 | - {$name} | |
| 65 | + class="' . $fieldHelpers->getAtomicCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '" | |
| 66 | + ' . $disabled . ' | |
| 67 | + value="' . $value . '" | |
| 68 | + ' . $check . ' | |
| 69 | + ' . $req . ' | |
| 70 | + ' . $name . ' | |
| 67 | 71 | /> |
| 68 | 72 | <label |
| 69 | - {$fieldHelpers->getCustomAttributes('cl')} | |
| 73 | + ' . $fieldHelpers->getCustomAttributes('cl') . ' | |
| 70 | 74 | data-cl |
| 71 | - for="{$rowID}-{$contentCount}-chk-{$key}" | |
| 72 | - class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}" | |
| 75 | + for="' . $rowID . '-' . $contentCount . '-chk-' . $key . '" | |
| 76 | + class="' . $fieldHelpers->getAtomicCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '" | |
| 73 | 77 | > |
| 74 | 78 | <span |
| 75 | - {$fieldHelpers->getCustomAttributes('bx')} | |
| 79 | + ' . $fieldHelpers->getCustomAttributes('bx') . ' | |
| 76 | 80 | data-bx |
| 77 | - class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getCustomClasses('bx')}" | |
| 81 | + class="' . $fieldHelpers->getAtomicCls('bx') . ' ' . $fieldHelpers->getCustomClasses('bx') . '" | |
| 78 | 82 | > |
| 79 | - <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}"> | |
| 80 | - <use data-ck-icn href="$href" class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" /> | |
| 83 | + <svg width="12" height="10" viewBox="0 0 12 10" class="' . $fieldHelpers->getAtomicCls('svgwrp') . ' ' . $fieldHelpers->getCustomClasses('svgwrp') . '" aria-hidden="true"> | |
| 84 | + <use data-ck-icn href="' . $href . '" class="' . $fieldHelpers->getAtomicCls('ck-icn') . ' ' . $fieldHelpers->getCustomClasses('ck-icn') . '" /> | |
| 81 | 85 | </svg> |
| 82 | 86 | </span> |
| 83 | 87 | <span |
| 84 | - {$fieldHelpers->getCustomAttributes('ct')} | |
| 85 | - class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}" | |
| 88 | + ' . $fieldHelpers->getCustomAttributes('ct') . ' | |
| 89 | + class="' . $fieldHelpers->getAtomicCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '" | |
| 86 | 90 | > |
| 87 | - {$fieldHelpers->kses_post($fieldHelpers->renderHTMR($opt->lbl))} | |
| 91 | + ' . $fieldHelpers->kses_post($fieldHelpers->renderHTMR($opt->lbl)) . ' | |
| 88 | 92 | </span> |
| 89 | 93 | </label> |
| 90 | - </div> | |
| 91 | -CHECKBOXOPTIONS; | |
| 94 | + </div>'; | |
| 92 | 95 | } |
| 93 | 96 | } |
| 94 | 97 | |
| 95 | 98 | //Other Option |
| 96 | - $optCount = property_exists($field, 'opt') ? count($field->opt) : 0; | |
| 97 | - $inputPh = isset($field->otherInpPh) ? "placeholder='{$fieldHelpers->esc_attr($field->otherInpPh)}'" : "placeholder='Other...'"; | |
| 99 | + $optCount = isset($field->opt) && is_countable($field->opt) ? count($field->opt) : 0; | |
| 98 | 100 | $inpReq = isset($field->valid->otherOptReq) ? ($field->valid->otherOptReq ? 'required' : '') : ''; |
| 101 | + $otherOptLbl = !empty($field->otherOptLbl) ? $field->otherOptLbl : __('Other...', 'bit-form'); | |
| 102 | + $inputPh = isset($field->otherInpPh) ? "placeholder='{$fieldHelpers->esc_attr($field->otherInpPh)}'" : "placeholder='{$otherOptLbl}'"; | |
| 99 | 103 | if (property_exists($field, 'addOtherOpt') && $field->addOtherOpt) { |
| 100 | - $checkBoxOptions .= <<<CHECKBOXOPTIONS | |
| 101 | - <div | |
| 102 | - {$fieldHelpers->getCustomAttributes('cw')} | |
| 103 | - class="{$fieldHelpers->getAtomicCls('cw')} {$fieldHelpers->getCustomClasses('cw')}" | |
| 104 | + $checkBoxOptions .= | |
| 105 | + '<div | |
| 106 | + ' . $fieldHelpers->getCustomAttributes('cw') . ' | |
| 107 | + class="' . $fieldHelpers->getAtomicCls('cw') . ' ' . $fieldHelpers->getCustomClasses('cw') . '" | |
| 104 | 108 | > |
| 105 | 109 | <input |
| 106 | - id="{$rowID}-{$contentCount}-chk-{$optCount}" | |
| 107 | - data-oopt="{$rowID}" | |
| 110 | + id="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '" | |
| 111 | + data-oopt="' . $rowID . '" | |
| 108 | 112 | type="checkbox" |
| 109 | - class="{$fieldHelpers->getAtomicCls('ci')} {$fieldHelpers->getCustomClasses('ci')}" | |
| 110 | - {$disabled} | |
| 113 | + class="' . $fieldHelpers->getAtomicCls('ci') . ' ' . $fieldHelpers->getCustomClasses('ci') . '" | |
| 114 | + ' . $disabled . ' | |
| 111 | 115 | value="" |
| 112 | - {$name} | |
| 116 | + ' . $name . ' | |
| 113 | 117 | /> |
| 114 | 118 | <label |
| 115 | - {$fieldHelpers->getCustomAttributes('cl')} | |
| 119 | + ' . $fieldHelpers->getCustomAttributes('cl') . ' | |
| 116 | 120 | data-cl |
| 117 | - for="{$rowID}-{$contentCount}-chk-{$optCount}" | |
| 118 | - class="{$fieldHelpers->getAtomicCls('cl')} {$fieldHelpers->getCustomClasses('cl')}" | |
| 121 | + for="' . $rowID . '-' . $contentCount . '-chk-' . $optCount . '" | |
| 122 | + class="' . $fieldHelpers->getAtomicCls('cl') . ' ' . $fieldHelpers->getCustomClasses('cl') . '" | |
| 119 | 123 | > |
| 120 | 124 | <span |
| 121 | - {$fieldHelpers->getCustomAttributes('ck')} | |
| 125 | + ' . $fieldHelpers->getCustomAttributes('ck') . ' | |
| 122 | 126 | data-bx |
| 123 | - class="{$fieldHelpers->getAtomicCls('bx')} {$fieldHelpers->getAtomicCls('ck')} {$fieldHelpers->getCustomClasses('ck')}" | |
| 127 | + class="' . $fieldHelpers->getAtomicCls('bx') . ' ' . $fieldHelpers->getAtomicCls('ck') . ' ' . $fieldHelpers->getCustomClasses('ck') . '" | |
| 124 | 128 | > |
| 125 | - <svg width="12" height="10" viewBox="0 0 12 10" class="{$fieldHelpers->getAtomicCls('svgwrp')} {$fieldHelpers->getCustomClasses('svgwrp')}"> | |
| 126 | - <use data-ck-icn href="#$rowID-ck-svg" class="{$fieldHelpers->getAtomicCls('ck-icn')} {$fieldHelpers->getCustomClasses('ck-icn')}" /> | |
| 129 | + <svg width="12" height="10" viewBox="0 0 12 10" class="' . $fieldHelpers->getAtomicCls('svgwrp') . ' ' . $fieldHelpers->getCustomClasses('svgwrp') . '" aria-hidden="true"> | |
| 130 | + <use data-ck-icn href="#' . $rowID . '-ck-svg" class="' . $fieldHelpers->getAtomicCls('ck-icn') . ' ' . $fieldHelpers->getCustomClasses('ck-icn') . '" /> | |
| 127 | 131 | </svg> |
| 128 | 132 | </span> |
| 129 | 133 | <span |
| 130 | - {$fieldHelpers->getCustomAttributes('ct')} | |
| 131 | - class="{$fieldHelpers->getAtomicCls('ct')} {$fieldHelpers->getCustomClasses('ct')}" | |
| 134 | + ' . $fieldHelpers->getCustomAttributes('ct') . ' | |
| 135 | + class="' . $fieldHelpers->getAtomicCls('ct') . ' ' . $fieldHelpers->getCustomClasses('ct') . '" | |
| 132 | 136 | > |
| 133 | - Other.. | |
| 137 | + ' . $otherOptLbl . ' | |
| 134 | 138 | </span> |
| 135 | 139 | </label> |
| 136 | - <div data-oinp-wrp class="{$fieldHelpers->getAtomicCls('other-inp-wrp')}"> | |
| 140 | + <div data-oinp-wrp class="' . $fieldHelpers->getAtomicCls('other-inp-wrp') . '"> | |
| 137 | 141 | <input |
| 138 | - data-bf-other-inp='{$rowID}-chk-{$optCount}' | |
| 142 | + data-bf-other-inp="' . $rowID . '-chk-' . $optCount . '" | |
| 139 | 143 | type="text" |
| 140 | - class="{$fieldHelpers->getAtomicCls('other-inp')} {$fieldHelpers->getCustomClasses('other-inp')}" | |
| 141 | - {$inpReq} | |
| 142 | - {$inputPh} | |
| 144 | + class="' . $fieldHelpers->getAtomicCls('other-inp') . ' ' . $fieldHelpers->getCustomClasses('other-inp') . '" | |
| 145 | + ' . $inpReq . ' | |
| 146 | + ' . $inputPh . ' | |
| 143 | 147 | /> |
| 144 | 148 | </div> |
| 145 | - </div> | |
| 146 | -CHECKBOXOPTIONS; | |
| 149 | + </div>'; | |
| 147 | 150 | } |
| 148 | 151 | |
| 149 | - return <<<CHECKBOXFIELD | |
| 150 | -<div | |
| 151 | - {$fieldHelpers->getCustomAttributes('cc')} | |
| 152 | - class="{$fieldHelpers->getAtomicCls('cc')} {$fieldHelpers->getCustomClasses('cc')}" | |
| 153 | -> | |
| 154 | - <svg class="{$fieldHelpers->getAtomicCls('cks')}"> | |
| 155 | - <symbol id="{$rowID}-ck-svg" viewBox="0 0 12 10"> | |
| 156 | - <polyline | |
| 157 | - class="{$fieldHelpers->getAtomicCls('ck-svgline')}" | |
| 158 | - points="1.5 6 4.5 9 10.5 1" | |
| 159 | - ></polygon> | |
| 160 | - </symbol> | |
| 161 | - </svg> | |
| 162 | - {$checkBoxOptions} | |
| 163 | -</div> | |
| 164 | -CHECKBOXFIELD; | |
| 152 | + $labelId = $fieldHelpers->getLabelId(); | |
| 153 | + $ariaDescribedBy = $fieldHelpers->ariaDescribedBy(); | |
| 154 | + $ariaRequired = $fieldHelpers->ariaRequired(); | |
| 155 | + | |
| 156 | + return sprintf( | |
| 157 | + '<div | |
| 158 | + %1$s | |
| 159 | + class="%2$s %3$s" | |
| 160 | + role="group" | |
| 161 | + aria-labelledby="%4$s" | |
| 162 | + %5$s | |
| 163 | + %6$s | |
| 164 | + > | |
| 165 | + <svg class="%7$s" aria-hidden="true"> | |
| 166 | + <symbol id="%8$s-ck-svg" viewBox="0 0 12 10"> | |
| 167 | + <polyline | |
| 168 | + class="%9$s" | |
| 169 | + points="1.5 6 4.5 9 10.5 1" | |
| 170 | + ></polyline> | |
| 171 | + </symbol> | |
| 172 | + </svg> | |
| 173 | + %10$s | |
| 174 | + </div>', | |
| 175 | + $fieldHelpers->getCustomAttributes('cc'), | |
| 176 | + $fieldHelpers->getAtomicCls('cc'), | |
| 177 | + $fieldHelpers->getCustomClasses('cc'), | |
| 178 | + $labelId, | |
| 179 | + $ariaDescribedBy, | |
| 180 | + $ariaRequired, | |
| 181 | + $fieldHelpers->getAtomicCls('cks'), | |
| 182 | + $rowID, | |
| 183 | + $fieldHelpers->getAtomicCls('ck-svgline'), | |
| 184 | + $checkBoxOptions | |
| 185 | + ); | |
| 165 | 186 | } |
| 166 | 187 | } |