mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 16:53:37 +02:00
Allow blank for requires helper
This commit is contained in:
parent
fa76d9079e
commit
f96398ea9f
1 changed files with 8 additions and 1 deletions
|
@ -84,12 +84,19 @@ class EppController < ApplicationController
|
||||||
# TODO: Add possibility to pass validations / options in the method
|
# TODO: Add possibility to pass validations / options in the method
|
||||||
|
|
||||||
def requires(*selectors)
|
def requires(*selectors)
|
||||||
|
options = selectors.extract_options!
|
||||||
|
allow_blank = options[:allow_blank] ||= false # allow_blank is false by default
|
||||||
|
|
||||||
el, missing = nil, nil
|
el, missing = nil, nil
|
||||||
selectors.each do |selector|
|
selectors.each do |selector|
|
||||||
full_selector = [@prefix, selector].compact.join(' ')
|
full_selector = [@prefix, selector].compact.join(' ')
|
||||||
el = params[:parsed_frame].css(full_selector).first
|
el = params[:parsed_frame].css(full_selector).first
|
||||||
|
|
||||||
|
if allow_blank
|
||||||
missing = el.nil?
|
missing = el.nil?
|
||||||
|
else
|
||||||
|
missing = el.present? ? el.text.blank? : true
|
||||||
|
end
|
||||||
epp_errors << {
|
epp_errors << {
|
||||||
code: '2003',
|
code: '2003',
|
||||||
msg: I18n.t('errors.messages.required_parameter_missing', key: full_selector)
|
msg: I18n.t('errors.messages.required_parameter_missing', key: full_selector)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue