docbrown/app/models/profile_field.rb
Ridhwana b0bacf60fb
Profile Fields Admin UI v2 (#9830)
* feat: add a select and a new text field

* feat: groups need to be unique and present

* feat: make the ui a little better

* chore: update the label

* chore: just present

* feat: add some js ( still a work in progress)

* feat: update the interface to work better :)

* chore: indent

* feat: make sure the toggles work

* chore: rename more aptly

* refactor: toggling pulled out into two functions

* refactor: move group form to a partial so that we can reuse it

* chore: move the js to the group form

* chore: update alignment and nav element

* chore: update text

* chore: update specs
2020-08-25 17:39:12 +02:00

35 lines
740 B
Ruby

class ProfileField < ApplicationRecord
before_create :generate_attribute_name
WORD_REGEX = /\w+/.freeze
# Key names follow the Rails form helpers
enum input_type: {
text_field: 0,
text_area: 1,
check_box: 2,
color_field: 3
}
enum display_area: {
header: 0,
left_sidebar: 1
}
validates :label, presence: true, uniqueness: { case_sensitive: false }
validates :attribute_name, presence: true, on: :update
validates :show_in_onboarding, inclusion: { in: [true, false] }
validates :group, presence: true
def type
return :boolean if check_box?
:string
end
private
def generate_attribute_name
self.attribute_name = label.titleize.scan(WORD_REGEX).join.underscore
end
end