File tree Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
Filter options
Expand file tree Collapse file tree 3 files changed +79
-0
lines changed
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace LaravelViewComponents \Components \Form ;
4
+
5
+ use Illuminate \Support \Str ;
6
+ use Illuminate \View \Component ;
7
+
8
+ class Textarea extends Component
9
+ {
10
+ /**
11
+ * The input id attribute.
12
+ *
13
+ * @var string
14
+ */
15
+ public $ id ;
16
+ /**
17
+ * The input name.
18
+ *
19
+ * @var string
20
+ */
21
+ public $ name ;
22
+ /**
23
+ * The input label.
24
+ *
25
+ * @var string
26
+ */
27
+ public $ label ;
28
+ /**
29
+ * The input placeholder.
30
+ *
31
+ * @var string
32
+ */
33
+ public $ placeholder ;
34
+
35
+ /**
36
+ * Create a new component instance.
37
+ *
38
+ * @param string $name
39
+ * @param string $label
40
+ * @param string $placeholder
41
+ *
42
+ * @return void
43
+ */
44
+ public function __construct ($ name = "text " , $ label = "Text Input " , $ placeholder = "Enter Text " )
45
+ {
46
+ $ this ->id = 'form- ' . Str::kebab (class_basename (get_class ($ this ))) . '- ' . md5 ($ name );
47
+ $ this ->name = $ name ;
48
+ $ this ->label = $ label ;
49
+ $ this ->placeholder = $ placeholder ;
50
+ }
51
+
52
+ /**
53
+ * Get the view / contents that represent the component.
54
+ *
55
+ * @return \Illuminate\View\View|string
56
+ */
57
+ public function render ()
58
+ {
59
+ return view ('components::form.textarea ' );
60
+ }
61
+ }
Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ public function boot()
30
30
Components \Form \Search::class,
31
31
Components \Form \Select::class,
32
32
Components \Form \Text::class,
33
+ Components \Form \Textarea::class,
33
34
Components \Form \Toggle::class,
34
35
Components \Form \Select \Images::class,
35
36
Components \Form \Select \Tags::class,
Original file line number Diff line number Diff line change
1
+ <div {{ $attributes -> merge ([' class' => ' form-group' ]) } } >
2
+ <label for =" {{ $id } }" class =" form-label" >{{ $label } } <span class =" form-label-description" >0/100</span ></label >
3
+ <textarea id =" {{ $id } }" name =" {{ $name } }" class =" form-control @error ($name ) is-invalid @enderror " placeholder =" {{ $placeholder } }" >{{ old ($name ) } } </textarea >
4
+ @error ($name )
5
+ <div class =" invalid-feedback" >{{ $message } } </div >
6
+ @enderror
7
+ </div >
8
+
9
+ @push (' scripts' )
10
+ <script type =" text/javascript" defer >
11
+ document .getElementById (" {{ $id } }" ).oninput = function () {
12
+ document .querySelector (" label[for={{ $id } } ]" ).querySelector (" span.form-label-description" ).innerText = this .value .length + " /200" ;
13
+ };
14
+
15
+ autosize (document .getElementById (" {{ $id } }" ));
16
+ </script >
17
+ @endpush
You can’t perform that action at this time.
0 commit comments