Skip to content

Commit

Permalink
added support for additional label classes (fixed #37)
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Oct 26, 2016
1 parent b2d3c96 commit 564326b
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
= 1.4.0 =
* Enhanced: all form settings except `submit_size`, `submit_type` and `required_html` can now be overridden on a per-field basis by providing the setting name and its intended value as a shortcode attribute
* Enhanced: a new value 'none' is now supported for the `layout` form setting which will prevent any wrapper from rendering; it is recommended to only use this for advanced field layouts
* Enhanced: a new attribute `label_class` can now be added to shortcodes for additional label classes
* Enhanced: `input_before` and `input_after` now support HTML by putting something like `{input_before}<span>Content before</span>{/input_before} into the content of a field shortcode (make sure to use curly braces); this method is now recommended and takes precedence over the old way
* Fixed: the label of the `free_text` option in radio buttons / checkboxes is now displayed correctly

Expand Down
12 changes: 9 additions & 3 deletions classes/CF7BS_Form_Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,22 @@ public function display( $echo = true ) {
}

if ( 'hidden' != $type ) {
$label_class = 'control-label';
if ( ! empty( $label_class ) ) {
$label_class .= ' ';
}

$input_div_class = '';
$input_class = $class;
if ( 'horizontal' == $form_layout ) {
$label_class .= ' control-label';
$classes = $this->get_column_width_classes( $form_label_width, $form_breakpoint, $grid_columns );
$label_class .= ' ' . $classes['label'];
$input_div_class = $classes['input'];
if ( empty( $label ) ) {
$input_div_class .= ' ' . $this->get_column_offset_class( $form_label_width, $form_breakpoint, $grid_columns );
}
} elseif( 'inline' == $form_layout ) {
$label_class .= ' sr-only';
if ( empty( $placeholder ) ) {
$placeholder = $label;
}
Expand Down Expand Up @@ -125,7 +130,7 @@ public function display( $echo = true ) {
} elseif( 'inline' == $form_layout ) {
$output .= '<div class="form-group' . $wrapper_class . $status . '">';
if ( ! empty( $label ) ) {
$output .= '<label class="sr-only"' . ( ! empty( $id ) ? ' for="' . esc_attr( $id ) . '"' : '' ) . '>' . esc_html( $label ) . $label_required . '</label>';
$output .= '<label class="' . esc_attr( $label_class ) . '"' . ( ! empty( $id ) ? ' for="' . esc_attr( $id ) . '"' : '' ) . '>' . esc_html( $label ) . $label_required . '</label>';
}
} else {
$output .= '<div class="form-group' . $wrapper_class . $status . '">';
Expand All @@ -134,7 +139,7 @@ public function display( $echo = true ) {
if ( in_array( $type, array( 'radio', 'checkbox' ) ) ) {
$rc_group_style = ' style="display:block;"';
}
$output .= '<label' . ( ! empty( $id ) ? ' for="' . esc_attr( $id ) . '"' : '' ) . $rc_group_style . '>' . esc_html( $label ) . $label_required . '</label>';
$output .= '<label class="' . esc_attr( $label_class ) . '"' . ( ! empty( $id ) ? ' for="' . esc_attr( $id ) . '"' : '' ) . $rc_group_style . '>' . esc_html( $label ) . $label_required . '</label>';
}
}
}
Expand Down Expand Up @@ -434,6 +439,7 @@ protected function get_defaults() {
'group_layout' => 'default', // default, inline, buttons
'group_type' => 'default', // only if group_layout==buttons
'wrapper_class' => '',
'label_class' => '',
'input_before' => '',
'input_after' => '',
'input_before_class' => 'input-group-addon',
Expand Down
1 change: 1 addition & 0 deletions modules/acceptance.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function cf7bs_acceptance_shortcode_handler( $tag ) {
'status' => $status,
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->name,
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ function cf7bs_checkbox_shortcode_handler( $tag ) {
'status' => $status,
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->get_class_option( $class . ' ' . $tag->name ),
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/date.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ function cf7bs_date_shortcode_handler( $tag ) {
'readonly' => $tag->has_option( 'readonly' ) ? true : false,
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->name,
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/file.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function cf7bs_file_shortcode_handler( $tag ) {
'status' => $status,
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->name,
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/number.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ function cf7bs_number_shortcode_handler( $tag ) {
'readonly' => $tag->has_option( 'readonly' ) ? true : false,
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->name,
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function cf7bs_quiz_shortcode_handler( $tag ) {
'maxlength' => $tag->get_maxlength_option(),
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->name,
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/really-simple-captcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ function cf7bs_captcha_shortcode_handler( $tag ) {
'maxlength' => $tag_obj->get_maxlength_option(),
'tabindex' => $tag_obj->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag_obj->name,
'label_class' => $tag_obj->get_option( 'label_class', 'class', true ),
'input_before' => $input_before,
'input_after' => $input_after,
'input_before_class'=> 'input-group-addon input-group-has-image',
Expand Down
1 change: 1 addition & 0 deletions modules/select.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ function cf7bs_select_shortcode_handler( $tag ) {
'status' => $status,
'tabindex' => $tag->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag->name,
'label_class' => $tag->get_option( 'label_class', 'class', true ),
), $tag->basetype, $tag->name ) );

$html = $field->display( false );
Expand Down
1 change: 1 addition & 0 deletions modules/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function cf7bs_text_shortcode_handler( $tag ) {
'maxlength' => $tag_obj->get_maxlength_option(),
'tabindex' => $tag_obj->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag_obj->name,
'label_class' => $tag_obj->get_option( 'label_class', 'class', true ),
'input_before' => $input_before,
'input_after' => $input_after,
), $tag_obj->basetype, $tag_obj->name ) );
Expand Down
1 change: 1 addition & 0 deletions modules/textarea.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ function cf7bs_textarea_shortcode_handler( $tag ) {
'maxlength' => $tag_obj->get_maxlength_option(),
'tabindex' => $tag_obj->get_option( 'tabindex', 'int', true ),
'wrapper_class' => $tag_obj->name,
'label_class' => $tag_obj->get_option( 'label_class', 'class', true ),
'rows' => $rows,
'input_before' => $input_before,
'input_after' => $input_after,
Expand Down

0 comments on commit 564326b

Please sign in to comment.