2014-06-23 7 views
2

Form::label 확인란과 라디오 입력을 사용하여 bootstrap에서 제안하는 마크 업을 생성 할 수 있습니까? 목표는 입력 필드를 id으로 첨부하는 대신 레이블 안에 넣는 것입니다. 나는 당신이 당신의 자신의 폼 매크로를 작성하고 그러나 당신이 좋아하는 HTML을 구축하는 것을 사용할 수 Form::radio라벨 및 라벨 안에 Laravel이있는

<div class="checkbox"> 
    <label> 
    <input type="checkbox" value=""> 
    Option one is this and that&mdash;be sure to include why it's great 
    </label> 
</div> 

<div class="radio"> 
    <label> 
    <input type="radio" name="optionsRadios" id="optionsRadios1" value="option1" checked> 
    Option one is this and that&mdash;be sure to include why it's great 
    </label> 
</div> 
<div class="radio"> 
    <label> 
    <input type="radio" name="optionsRadios" id="optionsRadios2" value="option2"> 
    Option two can be something else and selecting it will deselect option one 
    </label> 
</div> 
+1

. 다행히도 번들 구현은 이미 존재합니다 : http://bundles.laravel.com/search/tag/Bootstrap (bootsparks, bootstrapper) –

+2

Form 클래스를 확장하는 방법을 알아 냈습니다. 밝혀 졌 더라면 나는 단지 ': D – Unnawut

답변

2

주변의 마크 업을 하드 코딩하지 않도록하고 싶습니다. 당신은 당신이 원하는 가치를 전달할 수 있습니다 물론

{{ Form::bootCheck('i_dont_know_what_value_youd_like', 'Option one is this and that&mdash;be sure to include why it's great') }}

: 당신이보기에 다음과 같이 호출 할 수 있습니다 다음

Form::macro('bootCheckbox', function($value, $label) 
{ 
$html = '<div class="checkbox"><label><input type="checkbox" value="'; 
$html .= $value; 
$html .= '">'; 
$html .= $label; 
$html .= '</label></div>' 
return $html 
} 

그리고 :

http://laravel.com/docs/4.2/html#custom-macros

뭔가 같은 매크로를 사용하고 원하는대로 빌드하십시오 (매크로 쪽의 코드가 좋음). 위의 예는 표시된 것처럼 체크 상자를 출력해야하지만 너무 깨끗하지는 않습니다. 테스트하지 않았습니다.

어디서 코드를 삽입 할 것인가간에 링크를 연결하는 한 어디서나 삽입 할 수 있습니다. 내 양식 매크로 (좀 더 광범위)는 /app/start/form_macros.php에 있으며, 그 끝에 require dirname(__FILE__) . '/form_macros.php';을 추가하여 /app/start/global.php에 필요합니다.

3

옳은 방향으로 나를 이끌었던 그의 대답에 대한 성도 천재 덕분입니다. +1

그러나 여러 개의 세미콜론이 누락되어 있으며 checkbox 필드에 name 속성을 포함하지 않고 여러 줄에 걸쳐 $ html 문자열을 구분하여 읽기가 어렵습니다. 내가 조금을 다시 한

:

Form::macro('labelCheckbox', function($name, $value, $label) 
{ 
    $html = "<label> 
       <input name='$name' type='checkbox' value='$value' /> $label 
      </label>"; 

    return $html; 
}); 

다음보기에서 : 당신은`Form` 클래스를 확장 및 구현 input` 사용자 정의를`작성해야

{{ Form::labelCheckbox('fruits', 'apple', 'Apple') }} 
+0

에 대한 정보를 얻고 싶습니다. 하지만 당신이 조금 익숙하지 않은 것 같아요. 나는 코드가 테스트되지 않았고 깨끗하지 않다는 것을 대답했습니다. 어떤 더미라도 그것을 고칠 수 있어야합니다 xD –

+0

유효하지 않은 코드는 여전히 @theSaintGenius입니다.) –

+0

그래, 편집하지 않을 것입니다. 예를 들어 복사/붙여 넣기가 아닙니다. –