'text', 'name' => '', 'class' => '', 'wrap_class' => '', 'id' => '', 'placeholder' => '', 'title' => '', 'value' => '', 'required' => false, 'size' => '', // sm, lg, small, large 'clear_icon' => '', // true will show a clear icon, can't be used with input_group_right 'label' => '', 'label_after' => false, 'label_class' => '', 'label_col' => '2', 'label_type' => '', // top, horizontal, empty = hidden 'label_force_left' => false, // used to force checkbox label left when using horizontal // sets the label type, default: hidden. Options: hidden, top, horizontal, floating 'help_text' => '', 'validation_text' => '', 'validation_pattern' => '', 'no_wrap' => false, 'input_group_right' => '', 'input_group_left' => '', 'input_group_right_inside' => false, // forces the input group inside the input 'input_group_left_inside' => false, // forces the input group inside the input 'step' => '', 'switch' => false, // to show checkbox as a switch 'checked' => false, // set a checkbox or radio as selected 'password_toggle' => true, // toggle view/hide password 'element_require' => '', // [%element_id%] == "1" 'extra_attributes' => array(), // an array of extra attributes 'wrap_attributes' => array() ); /** * Parse incoming $args into an array and merge it with $defaults */ $args = wp_parse_args( $args, $defaults ); $output = ''; if ( ! empty( $args['type'] ) ) { // hidden label option needs to be empty $args['label_type'] = $args['label_type'] == 'hidden' ? '' : $args['label_type']; $type = sanitize_html_class( $args['type'] ); $help_text = ''; $label = ''; $label_after = $args['label_after']; $label_args = array( 'title' => $args['label'], 'for' => $args['id'], 'class' => $args['label_class'] . " ", 'label_type' => $args['label_type'], 'label_col' => $args['label_col'] ); // floating labels need label after if ( $args['label_type'] == 'floating' && $type != 'checkbox' ) { $label_after = true; $args['placeholder'] = ' '; // set the placeholder not empty so the floating label works. } // size $size = ''; if ( $args['size'] == 'lg' || $args['size'] == 'large' ) { $size = 'lg'; $args['class'] .= ' form-control-lg'; }elseif ( $args['size'] == 'sm' || $args['size'] == 'small' ) { $size = 'sm'; $args['class'] .= ' form-control-sm'; } // clear function $clear_function = 'jQuery(this).parent().parent().find(\'input\').val(\'\');'; // Some special sauce for files if ( $type == 'file' ) { $label_after = true; // if type file we need the label after $args['class'] .= ' custom-file-input '; } elseif ( $type == 'checkbox' ) { $label_after = true; // if type file we need the label after $args['class'] .= ' custom-control-input '; } elseif ( $type == 'datepicker' || $type == 'timepicker' ) { $type = 'text'; $args['class'] .= ' bg-initial '; // @todo not sure why we have this? $clear_function .= "jQuery(this).parent().parent().find('input[name=\'" . esc_attr( $args['name'] ) . "\']').trigger('change');"; $args['extra_attributes']['data-aui-init'] = 'flatpickr'; // set a way to clear field if empty if ( $args['input_group_right'] === '' && $args['clear_icon'] !== false ) { $args['input_group_right_inside'] = true; $args['clear_icon'] = true; } // enqueue the script $aui_settings = AyeCode_UI_Settings::instance(); $aui_settings->enqueue_flatpickr(); } elseif ( $type == 'iconpicker' ) { $type = 'text'; //$args['class'] .= ' aui-flatpickr bg-initial '; // $args['class'] .= ' bg-initial '; $args['extra_attributes']['data-aui-init'] = 'iconpicker'; $args['extra_attributes']['data-placement'] = 'bottomRight'; $args['input_group_right'] = ''; // $args['input_group_right_inside'] = true; // enqueue the script $aui_settings = AyeCode_UI_Settings::instance(); $aui_settings->enqueue_iconpicker(); } if ( $type == 'checkbox' && !empty($args['name'] ) && strpos($args['name'], '[') === false ) { $output .= ''; } // allow clear icon if ( $args['input_group_right'] === '' && $args['clear_icon'] ) { $font_size = $size == 'sm' ? '1.3' : ( $size == 'lg' ? '1.65' : '1.5' ); $args['input_group_right_inside'] = true; $args['input_group_right'] = ''; } // open/type $output .= ' $output, 'class' => 'form-group custom-file' ) ); } elseif ( $type == 'checkbox' ) { $label_args['title'] = $args['label']; $label_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ); $label = !empty( $args['label_force_left'] ) ? self::label( $label_args, 'cb' ) : '
'; $switch_size_class = $args['switch'] && !is_bool( $args['switch'] ) ? ' custom-switch-'.esc_attr( $args['switch'] ) : ''; $wrap_class = $args['switch'] ? 'custom-switch'.$switch_size_class : 'custom-checkbox'; if ( ! empty( $args['label_force_left'] ) ) { $wrap_class .= ' d-flex align-content-center'; $label = str_replace("custom-control-label","", self::label( $label_args, 'cb' ) ); } $output = self::wrap( array( 'content' => $output, 'class' => 'custom-control ' . $wrap_class ) ); if ( $args['label_type'] == 'horizontal' ) { $input_col = AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ); $output = $label . '
' . $output . '
'; } } elseif ( $type == 'password' && $args['password_toggle'] && ! $args['input_group_right'] ) { // allow password field to toggle view $args['input_group_right'] = ''; } // input group wraps if ( $args['input_group_left'] || $args['input_group_right'] ) { $w100 = strpos( $args['class'], 'w-100' ) !== false ? ' w-100' : ''; $group_size = $size == 'lg' ? ' input-group-lg' : ''; $group_size = !$group_size && $size == 'sm' ? ' input-group-sm' : $group_size; if ( $args['input_group_left'] ) { $output = self::wrap( array( 'content' => $output, 'class' => $args['input_group_left_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, 'input_group_left' => $args['input_group_left'], 'input_group_left_inside' => $args['input_group_left_inside'] ) ); } if ( $args['input_group_right'] ) { $output = self::wrap( array( 'content' => $output, 'class' => $args['input_group_right_inside'] ? 'input-group-inside position-relative' . $w100 . $group_size : 'input-group' . $group_size, 'input_group_right' => $args['input_group_right'], 'input_group_right_inside' => $args['input_group_right_inside'] ) ); } } if ( ! $label_after ) { $output .= $help_text; } if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { $output = self::wrap( array( 'content' => $output, 'class' => AUI_Component_Helper::get_column_class( $args['label_col'], 'input' ) ) ); } if ( ! $label_after ) { $output = $label . $output; } // wrap if ( ! $args['no_wrap'] ) { $form_group_class = $args['label_type'] == 'floating' && $type != 'checkbox' ? 'form-label-group' : 'form-group'; $wrap_class = $args['label_type'] == 'horizontal' ? $form_group_class . ' row' : $form_group_class; $wrap_class = ! empty( $args['wrap_class'] ) ? $wrap_class . " " . $args['wrap_class'] : $wrap_class; $output = self::wrap( array( 'content' => $output, 'class' => $wrap_class, 'element_require' => $args['element_require'], 'argument_id' => $args['id'], 'wrap_attributes' => $args['wrap_attributes'], ) ); } } return $output; } public static function label( $args = array(), $type = '' ) { // $defaults = array( 'title' => 'div', 'for' => '', 'class' => '', 'label_type' => '', // empty = hidden, top, horizontal 'label_col' => '', ); /** * Parse incoming $args into an array and merge it with $defaults */ $args = wp_parse_args( $args, $defaults ); $output = ''; if ( $args['title'] ) { // maybe hide labels //@todo set a global option for visibility class if ( $type == 'file' || $type == 'checkbox' || $type == 'radio' || ! empty( $args['label_type'] ) ) { $class = $args['class']; } else { $class = 'sr-only ' . $args['class']; } // maybe horizontal if ( $args['label_type'] == 'horizontal' && $type != 'checkbox' ) { $class .= ' ' . AUI_Component_Helper::get_column_class( $args['label_col'], 'label' ) . ' col-form-label'; } // open $output .= '