Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 828be8a

Browse filesBrowse files
author
Daniel Wiser
committed
Add Textarea
1 parent 22415b4 commit 828be8a
Copy full SHA for 828be8a

File tree

Expand file treeCollapse file tree

3 files changed

+79
-0
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+79
-0
lines changed

‎src/Components/Form/Textarea.php

Copy file name to clipboard
+61Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

‎src/FormServiceProvider.php

Copy file name to clipboardExpand all lines: src/FormServiceProvider.php
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public function boot()
3030
Components\Form\Search::class,
3131
Components\Form\Select::class,
3232
Components\Form\Text::class,
33+
Components\Form\Textarea::class,
3334
Components\Form\Toggle::class,
3435
Components\Form\Select\Images::class,
3536
Components\Form\Select\Tags::class,

‎src/Views/form/textarea.blade.php

Copy file name to clipboard
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.