Sha256: ef005b6f137b7fb289ed42ae84223baee61026d1ed6fad696876630e9645f261
Contents?: true
Size: 1.91 KB
Versions: 5
Compression:
Stored size: 1.91 KB
Contents
# -*- encoding: utf-8 -*- # -*- frozen_string_literal: true -*- # -*- warn_indent: true -*- module RailsBootstrapForm module Helpers module Labels extend ActiveSupport::Concern def self.included(base_class) def draw_label(attribute, options, bootstrap_options) unless bootstrap_options.skip_label? && !bootstrap_options.floating? label_options = { class: label_classes(attribute, options, bootstrap_options) } label_options[:for] = options[:id] if options[:id].present? label_text = label_text(attribute, bootstrap_options) label(attribute, label_text, label_options) end end def label_classes(attribute, options, bootstrap_options) classes = [] classes << label_layout_classes(bootstrap_options) classes << bootstrap_options.additional_label_class classes << bootstrap_options.hide_class if hide_class_required?(bootstrap_options) classes << "required" if is_field_required?(attribute, options) classes << "is-invalid" if is_invalid?(attribute) classes.flatten.compact end def label_layout_classes(bootstrap_options) if bootstrap_options.layout_horizontal? [bootstrap_options.label_col_class, bootstrap_options.label_col_wrapper_class] else bootstrap_options.label_class end end def label_text(attribute, bootstrap_options) bootstrap_options.label_text || object&.class.try(:human_attribute_name, attribute) end def hide_class_required?(bootstrap_options) bootstrap_options.hide_label? || (bootstrap_options.layout_inline? && !bootstrap_options.floating?) end private :draw_label, :label_classes, :label_text, :label_layout_classes, :hide_class_required? end end end end
Version data entries
5 entries across 5 versions & 1 rubygems