@@ -29,35 +29,33 @@ function makeBootstrap4(Form $form)
2929 $ renderer ->wrappers ['control ' ]['description ' ] = 'span class=form-text ' ;
3030 $ renderer ->wrappers ['control ' ]['errorcontainer ' ] = 'span class=form-control-feedback ' ;
3131
32- $ form ->onRender [] = function ($ form ) {
33- foreach ($ form ->getControls () as $ control ) {
34- $ type = $ control ->getOption ('type ' );
35- if ($ type === 'button ' ) {
36- $ control ->getControlPrototype ()->addClass (empty ($ usedPrimary ) ? 'btn btn-primary ' : 'btn btn-secondary ' );
37- $ usedPrimary = true ;
38-
39- } elseif (in_array ($ type , ['text ' , 'textarea ' , 'select ' ], true )) {
40- $ control ->getControlPrototype ()->addClass ('form-control ' );
41-
42- } elseif ($ type === 'file ' ) {
43- $ control ->getControlPrototype ()->addClass ('form-control-file ' );
44-
45- } elseif (in_array ($ type , ['checkbox ' , 'radio ' ], true )) {
46- if ($ control instanceof Nette \Forms \Controls \Checkbox) {
47- $ control ->getLabelPrototype ()->addClass ('form-check-label ' );
48- } else {
49- $ control ->getItemLabelPrototype ()->addClass ('form-check-label ' );
50- }
51- $ control ->getControlPrototype ()->addClass ('form-check-input ' );
52- $ control ->getSeparatorPrototype ()->setName ('div ' )->addClass ('form-check ' );
32+ foreach ($ form ->getControls () as $ control ) {
33+ $ type = $ control ->getOption ('type ' );
34+ if ($ type === 'button ' ) {
35+ $ control ->getControlPrototype ()->addClass (empty ($ usedPrimary ) ? 'btn btn-primary ' : 'btn btn-secondary ' );
36+ $ usedPrimary = true ;
37+
38+ } elseif (in_array ($ type , ['text ' , 'textarea ' , 'select ' ], true )) {
39+ $ control ->getControlPrototype ()->addClass ('form-control ' );
40+
41+ } elseif ($ type === 'file ' ) {
42+ $ control ->getControlPrototype ()->addClass ('form-control-file ' );
43+
44+ } elseif (in_array ($ type , ['checkbox ' , 'radio ' ], true )) {
45+ if ($ control instanceof Nette \Forms \Controls \Checkbox) {
46+ $ control ->getLabelPrototype ()->addClass ('form-check-label ' );
47+ } else {
48+ $ control ->getItemLabelPrototype ()->addClass ('form-check-label ' );
5349 }
50+ $ control ->getControlPrototype ()->addClass ('form-check-input ' );
51+ $ control ->getSeparatorPrototype ()->setName ('div ' )->addClass ('form-check ' );
5452 }
55- };
53+ }
5654}
5755
5856
5957$ form = new Form ;
60- makeBootstrap4 ( $ form) ;
58+ $ form-> onRender [] = ' makeBootstrap4 ' ;
6159
6260$ form ->addGroup ('Personal data ' );
6361$ form ->addText ('name ' , 'Your name ' )
@@ -99,7 +97,7 @@ function makeBootstrap4(Form $form)
9997<meta charset="utf-8">
10098<title>Nette Forms & Bootstrap v4 rendering example</title>
10199
102- <link rel="stylesheet" href="http ://v4-alpha.getbootstrap .com/dist /css/bootstrap.min.css">
100+ <link rel="stylesheet" href="https ://maxcdn.bootstrapcdn .com/bootstrap/4.0.0-beta.2 /css/bootstrap.min.css">
103101
104102<div class="container">
105103 <h1>Nette Forms & Bootstrap v4 rendering example</h1>
0 commit comments