2012-02-28 6 views
5

내부 입력 태그,이처럼 보이는 마크 업을 생성합니다 : I는 입력 태그 내부 자체 인 마크 업을 좀하고 싶습니다 SimpleForm 2 : 기본 simple_form 2 래퍼를 사용하여 래퍼

<div class="..."> 
    <label>...</label> 
    <input ... /> 
</div> 

다음과 같은 래퍼 :

<div class="..."> 
    <label>...</label> 
    <div class="..."> 
    <input ... /> 
    </div> 
</div> 

이 동작을 위해 사용자 지정 구성 요소를 만들어야합니까?

감사합니다.

니콜라스.

답변

7

확인이 아웃 :

래퍼 API는 아직 잘 문서화되어 있지 않습니다,하지만 난 그것을 알아 내려고 시간을 보냈어요. 다음은 simple_form 이니셜 라이저 안에서 설정할 수있는 간단한 예제입니다. 이 도움이

<%= simple_form_for @user, wrapper: 'WHATEVER_YOU_CALLED_YOUR_WRAPPER' do |form| %> 
<%end%> 

희망 : 폼을 만들 때

# Use this setup block to configure all options available in SimpleForm. 
SimpleForm.setup do |config| 
    # Wrappers are used by the form builder to generate a complete input. 
    # You can remove any component from the wrapper, change the order or even 
    # add your own to the stack. The options given to the wrappers method 
    # are used to wrap the whole input (if any exists). 

    config.wrappers :GIVE_YOUR_WRAPPER_A_NAME, :class => 'clearfix', :error_class => nil do |b| 
    b.use :placeholder 
    b.use :label 
    b.use :tag => 'div', :class => 'WHATEVER_YOU_WANT_TO_CALL_IT' do |ba| 
     ba.use :input 
     ba.use :error, :tag => :span, :class => :'help-inline' 
     ba.use :hint, :tag => :span, :class => :'help-block' 
    end 
    end 
end 

그런 다음, 당신이 사용하고자하는 래퍼를 지정합니다.

+0

그 것이었다! 나는 당신이 명시 적으로 "use : input"을 정의하여 입력 태그의 위치를 ​​제어 할 수 있다는 것을 몰랐다. 이것은 문서에 기록되어야합니다. 큰! –