Class: Bureaucrat::Fields::RegexField

Inherits:
CharField show all
Defined in:
lib/bureaucrat/fields.rb

Overview

DateField TimeField DateTimeField

Instance Attribute Summary

Attributes inherited from CharField

#max_length, #min_length

Attributes inherited from Field

#error_messages, #help_text, #hidden_widget, #initial, #label, #required, #show_hidden_initial, #validators, #widget

Instance Method Summary collapse

Methods inherited from CharField

#to_object, #widget_attrs

Methods inherited from Field

#bound_data, #clean, #default_error_messages, #default_hidden_widget, #default_validators, #default_widget, #initialize_copy, #populate_object, #prepare_value, #run_validators, #to_object, #validate, #widget_attrs

Constructor Details

#initialize(regex, options = {}) ⇒ RegexField

Returns a new instance of RegexField.



358
359
360
361
362
363
364
365
366
367
368
369
370
371
# File 'lib/bureaucrat/fields.rb', line 358

def initialize(regex, options={})
  error_message = options.delete(:error_message)

  if error_message
    options[:error_messages] ||= {}
    options[:error_messages][:invalid] = error_message
  end

  super(options)

  @regex = regex

  validators << Validators::RegexValidator.new(regex: regex)
end