5050 </div >
5151 </div >
5252
53- <hr />
53+ <hr />
5454
5555 <h3 >Add fields</h3 >
5656
5757 <table class =" table" >
5858 <tbody id =" generator" >
59- <tr >
60- <td >Show in list</td >
61- <td ></td >
62- <td ></td >
63- <td ></td >
64- <td ></td >
65- <td ></td >
66- </tr >
6759 @if (old (' f_type' ) )
6860 @foreach (old (' f_type' ) as $index => $fieldName )
6961 @include (' tpl::crud_field_line' , [' index' => $index ] )
7668
7769 <div class =" form-group" >
7870 <div class =" col-md-12" >
79- <button type =" button" id =" addField" class =" btn btn-success" ><i class =" fa fa-plus" ></i > Add one more field
80- </button >
71+ <button type =" button" id =" addField" class =" btn btn-success" ><i class =" fa fa-plus" ></i > Add one more field</button >
8172 </div >
8273 </div >
8374
84- <hr />
75+ <hr />
8576
8677 <div class =" form-group" >
8778 <div class =" col-md-12" >
9788 @include (' tpl::crud_field_line' , [' index' => ' ' ] )
9889 </tbody >
9990 </table >
100-
101- <!-- Select for relationship column-->
102- @foreach ($models as $key => $model )
103- <select name =" f_relationship_field[{{ $key } } ]" class =" form-control relationship-field rf-{{ $key } }" >
104- <option value =" " >Select display field</option >
105- @foreach ($model as $key2 => $option )
106- <option value =" {{ $option } }"
107- @if ($option == old (' f_relationship_field.' . $key ) ) selected @endif >{{ $option } } </option >
108- @endforeach
109- </select >
110- @endforeach
111- <!-- /Select for relationship column-->
11291 </div >
11392
11493@endsection
11594
11695@section (' javascript' )
11796 <script >
118- function typeChange (e ) {
119- var val = $ (e).val ();
120- // Hide all possible outputs
121- $ (e).parent ().parent ().find (' .value' ).hide ();
122- $ (e).parent ().parent ().find (' .default_c' ).hide ();
123- $ (e).parent ().parent ().find (' .relationship' ).hide ();
124- $ (e).parent ().parent ().find (' .title' ).show ().val (' ' );
125- $ (e).parent ().parent ().find (' .texteditor' ).hide ();
126- $ (e).parent ().parent ().find (' .size' ).hide ();
127-
128- // Show a checbox which enables/disables showing in list
129- $ (e).parent ().parent ().parent ().find (' .show2' ).show ();
130- $ (e).parent ().parent ().parent ().find (' .show_hid' ).val (1 );
131- switch (val) {
132- case ' radio' :
133- $ (e).parent ().parent ().find (' .value' ).show ();
134- break ;
135- case ' checkbox' :
136- $ (e).parent ().parent ().find (' .default_c' ).show ();
137- break ;
138- case ' relationship' :
139- $ (e).parent ().parent ().find (' .relationship' ).show ();
140- $ (e).parent ().parent ().find (' .title' ).hide ().val (' -' );
141- break ;
142- case ' textarea' :
143- $ (e).parent ().parent ().find (' .show2' ).hide ();
144- $ (e).parent ().parent ().find (' .show_hid' ).val (0 );
145- $ (e).parent ().parent ().find (' .texteditor' ).show ();
146- break ;
147- case ' file' :
148- $ (e).parent ().parent ().find (' .size' ).show ();
149- break ;
150- }
151- }
152-
153- function relationshipChange (e ) {
154- var val = $ (e).val ();
155- $ (e).parent ().parent ().find (' .relationship-field' ).remove ();
156- var select = $ (' .rf-' + val).clone ();
157- $ (e).parent ().parent ().find (' .relationship-holder' ).html (select);
158- }
159-
16097 $ (document ).ready (function () {
161- $ (' .type' ).each (function () {
162- typeChange ($ (this ))
163- });
164- $ (' .relationship' ).each (function () {
165- relationshipChange ($ (this ))
166- });
167-
168- $ (' .show2' ).change (function () {
169- var checked = $ (this ).is (" :checked" );
170- if (checked) {
171- $ (this ).parent ().find (' .show_hid' ).val (1 );
172- } else {
173- $ (this ).parent ().find (' .show_hid' ).val (0 );
174- }
175- });
176-
17798 // Add new row to the table of fields
17899 $ (' #addField' ).click (function () {
179100 var line = $ (' #line' ).html ();
180101 var table = $ (' #generator' );
181102 table .append (line);
182103 });
183-
184104 // Remove row from the table of fields
185105 $ (document ).on (' click' , ' .rem' , function () {
186106 $ (this ).parent ().parent ().remove ();
187107 });
188108
189109 $ (document ).on (' change' , ' .type' , function () {
190- typeChange ($ (this ))
191- });
192- $ (document ).on (' change' , ' .relationship' , function () {
193- relationshipChange ($ (this ))
110+ var val = $ (this ).val ();
111+ if (val == ' radio' || val == ' checkbox' ) {
112+ $ (this ).parent ().parent ().find (' .value' ).show ();
113+ }else {
114+ $ (this ).parent ().parent ().find (' .value' ).hide ();
115+ }
194116 });
195117 });
196-
197118 </script >
198119@stop
0 commit comments