← All changes
|
modules/option-field/blocks/checkbox/block-render.php
+14
-12
3.6.4
→
3.6.6
View file →
| @@ -151,28 +151,23 @@ | ||
| 151 | 151 | return $html; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | protected function render_custom_option(): string { |
| 155 | - $html = '<div class="jet-form-builder__field-wrap checkboxes-wrap checkradio-wrap custom-option">'; | |
| 156 | - $class_name = $this->args['class_name'] ?? ''; | |
| 155 | + $html = '<div class="jet-form-builder__field-wrap checkboxes-wrap checkradio-wrap custom-option">'; | |
| 156 | + $has_options = ! empty( $this->args['field_options'] ); | |
| 157 | 157 | |
| 158 | 158 | $name = esc_attr( $this->block_type->get_field_name() . $this->get_name_suffix() ); |
| 159 | 159 | $checkbox = sprintf( |
| 160 | - '<input %1$s value="">', | |
| 160 | + '<input %1$s %2$s value="">', | |
| 161 | 161 | Builder_Helper::attrs( |
| 162 | 162 | array( |
| 163 | 163 | array( 'type', 'checkbox' ), |
| 164 | - array( 'checked', 'checked' ), | |
| 164 | + array( 'checked', $has_options ? 'checked' : '' ), | |
| 165 | 165 | array( 'data-field-name', esc_attr( $this->args['name'] ) ), |
| 166 | 166 | array( 'data-custom', 1 ), |
| 167 | - array( | |
| 168 | - 'class', | |
| 169 | - 'jet-form-builder__field checkboxes-field checkradio-field' . ( | |
| 170 | - $class_name ? " {$class_name}" : '' | |
| 171 | - ), | |
| 172 | - ), | |
| 173 | 167 | ) |
| 174 | - ) | |
| 168 | + ), | |
| 169 | + $this->get_attributes_string_save() | |
| 175 | 170 | ); |
| 176 | 171 | |
| 177 | 172 | $input = sprintf( |
| 178 | 173 | '<input %s>', |
| @@ -206,8 +201,12 @@ | ||
| 206 | 201 | $custom_label, |
| 207 | 202 | $html . $item_template . '</div>' |
| 208 | 203 | ); |
| 209 | 204 | |
| 205 | + if ( ! $has_options ) { | |
| 206 | + return $html . $item_template . '</div>' . $html . $button . '</div>'; | |
| 207 | + } | |
| 208 | + | |
| 210 | 209 | $html .= $button . '</div>'; |
| 211 | 210 | |
| 212 | 211 | return $html; |
| 213 | 212 | } |
| @@ -212,9 +211,12 @@ | ||
| 212 | 211 | return $html; |
| 213 | 212 | } |
| 214 | 213 | |
| 215 | 214 | public function get_name_suffix(): string { |
| 216 | - return count( $this->args['field_options'] ) > 1 ? '[]' : ''; | |
| 215 | + return ( | |
| 216 | + count( $this->args['field_options'] ) > 1 | |
| 217 | + || ! empty( $this->args['custom_option']['allow'] ) | |
| 218 | + ) ? '[]' : ''; | |
| 217 | 219 | } |
| 218 | 220 | |
| 219 | 221 | /** |
| 220 | 222 | * @see \Jet_Form_Builder\Blocks\Render\Calculated_Field_Render::get_fields_label_tag |