유효성 검사가 통과되지 않으면 레일스가 코드를 변경하는 것을 어떻게 멈 춥니 다.레일은 div로 필드를 랩핑합니다.
때마다 레일 I 작동 fields_with_error
클래스
.fields_with_error{ display: inline }
을 편집 할 수 있습니다
<div class='field_with_error'>...</div>
내 필드를 래핑하지만
유효성 검사가 통과되지 않으면 레일스가 코드를 변경하는 것을 어떻게 멈 춥니 다.레일은 div로 필드를 랩핑합니다.
때마다 레일 I 작동 fields_with_error
클래스
.fields_with_error{ display: inline }
을 편집 할 수 있습니다
<div class='field_with_error'>...</div>
내 필드를 래핑하지만
그것의 좋은 해키입니다. 이 작업을 수행하는 대신 CSS를 사용하십시오. 내가 느끼는
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag| "<span class='field_error'>#{html_tag}</span>" end
는 :
내가 environment.rb에이를 사용하여 더 해키입니다. 더 이상 해킹 ;-)
#
# Fix annoying <div class="fieldsWithError"> wrapping after validation
# http://dev.rubyonrails.org/ticket/3587
#
ActionView::Base.field_error_proc = Proc.new { |html_tag, instance|
msg = instance.error_message
if html_tag =~ /<(input|textarea|select)[>]+class=/
class_attribute = html_tag =~ /class=['"]/
html_tag.insert(class_attribute + 7, "error ")
elsif html_tag =~ /<(input|textarea|select)/
first_whitespace = html_tag =~ /\s/
html_tag[first_whitespace] = " class='error' "
end
html_tag
}
또한 jQuery를 사용하여 수행 할 수도 있습니다. 여전히 해킹이 아니라 작동하는 것처럼 느껴집니다.
실제로 이것은 매우 예외적 인 경우에 도움이 될 수 있습니다. 감사! – pierrea
JS를 실행하지 않는 사용자가있는 경우 다른 행동을 보입니다. 이를 위해 JS를 사용하는 것은 과도합니다. –
이 문제를 방지하기위한 방법이 없습니까? – ohhh