Skip to content

Commit 0766190

Browse files
committed
FormOption improvements and tests
1 parent f7de579 commit 0766190

File tree

2 files changed

+120
-11
lines changed

2 files changed

+120
-11
lines changed

src/Html/Editor/FormOptions.php

Lines changed: 70 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ public static function make(array $attributes = []): static
1919
}
2020

2121
/**
22-
* @param int $value
22+
* @param int|string|null $value
2323
* @return $this
24+
* @see https://editor.datatables.net/reference/type/form-options#focus
2425
*/
25-
public function focus(int $value = 0): static
26+
public function focus(int|string $value = null): static
2627
{
2728
$this->attributes['focus'] = $value;
2829

@@ -32,17 +33,19 @@ public function focus(int $value = 0): static
3233
/**
3334
* @param bool $value
3435
* @return $this
36+
* @see https://editor.datatables.net/reference/type/form-options#nest
3537
*/
36-
public function message(bool $value = false): static
38+
public function nest(bool $value): static
3739
{
38-
$this->attributes['message'] = $value;
40+
$this->attributes['nest'] = $value;
3941

4042
return $this;
4143
}
4244

4345
/**
4446
* @param string $value
4547
* @return $this
48+
* @see https://editor.datatables.net/reference/type/form-options#onBackground
4649
*/
4750
public function onBackground(string $value = 'blur'): static
4851
{
@@ -54,6 +57,7 @@ public function onBackground(string $value = 'blur'): static
5457
/**
5558
* @param string $value
5659
* @return $this
60+
* @see https://editor.datatables.net/reference/type/form-options#onBlur
5761
*/
5862
public function onBlur(string $value = 'close'): static
5963
{
@@ -65,6 +69,7 @@ public function onBlur(string $value = 'close'): static
6569
/**
6670
* @param string $value
6771
* @return $this
72+
* @see https://editor.datatables.net/reference/type/form-options#onComplete
6873
*/
6974
public function onComplete(string $value = 'close'): static
7075
{
@@ -76,6 +81,7 @@ public function onComplete(string $value = 'close'): static
7681
/**
7782
* @param string $value
7883
* @return $this
84+
* @see https://editor.datatables.net/reference/type/form-options#onEsc
7985
*/
8086
public function onEsc(string $value = 'close'): static
8187
{
@@ -87,6 +93,7 @@ public function onEsc(string $value = 'close'): static
8793
/**
8894
* @param string $value
8995
* @return $this
96+
* @see https://editor.datatables.net/reference/type/form-options#onFieldError
9097
*/
9198
public function onFieldError(string $value = 'focus'): static
9299
{
@@ -98,6 +105,7 @@ public function onFieldError(string $value = 'focus'): static
98105
/**
99106
* @param string $value
100107
* @return $this
108+
* @see https://editor.datatables.net/reference/type/form-options#onReturn
101109
*/
102110
public function onReturn(string $value = 'submit'): static
103111
{
@@ -109,6 +117,7 @@ public function onReturn(string $value = 'submit'): static
109117
/**
110118
* @param string $value
111119
* @return $this
120+
* @see https://editor.datatables.net/reference/type/form-options#submit
112121
*/
113122
public function submit(string $value = 'changed'): static
114123
{
@@ -118,34 +127,84 @@ public function submit(string $value = 'changed'): static
118127
}
119128

120129
/**
121-
* @param bool $value
130+
* @param string $value
122131
* @return $this
132+
* @see https://editor.datatables.net/reference/type/form-options#scope
123133
*/
124-
public function title(bool $value = false): static
134+
public function scope(string $value = 'row'): static
125135
{
126-
$this->attributes['title'] = $value;
136+
$this->attributes['scope'] = $value;
127137

128138
return $this;
129139
}
130140

131141
/**
132-
* @param bool $value
142+
* @param array|string $value
143+
* @return $this
144+
* @see https://editor.datatables.net/reference/type/form-options#buttons
145+
*/
146+
public function buttons(array|string $value): static
147+
{
148+
$this->attributes['buttons'] = $value;
149+
150+
return $this;
151+
}
152+
/**
153+
* @param string $value
133154
* @return $this
155+
* @see https://editor.datatables.net/reference/type/form-options#drawType
134156
*/
135-
public function drawType(bool $value = false): static
157+
public function drawType(string $value = ''): static
136158
{
137159
$this->attributes['drawType'] = $value;
138160

139161
return $this;
140162
}
141163

164+
/**
165+
* @param bool|string $value
166+
* @return $this
167+
* @see https://editor.datatables.net/reference/type/form-options#message
168+
*/
169+
public function message(bool|string $value = ''): static
170+
{
171+
$this->attributes['message'] = $value;
172+
173+
return $this;
174+
}
175+
176+
/**
177+
* @param int|string $value
178+
* @return $this
179+
* @see https://editor.datatables.net/reference/type/form-options#submitTrigger
180+
*/
181+
public function submitTrigger(int|string $value): static
182+
{
183+
$this->attributes['submitTrigger'] = $value;
184+
185+
return $this;
186+
}
187+
142188
/**
143189
* @param string $value
144190
* @return $this
191+
* @see https://editor.datatables.net/reference/type/form-options#submitHtml
145192
*/
146-
public function scope(string $value = 'row'): static
193+
public function submitHtml(string $value): static
147194
{
148-
$this->attributes['scope'] = $value;
195+
$this->attributes['submitHtml'] = $value;
196+
197+
return $this;
198+
}
199+
200+
/**
201+
* @param bool|string $value
202+
* @return $this
203+
* @see https://editor.datatables.net/reference/type/form-options#title
204+
*/
205+
public function title(bool|string $value): static
206+
{
207+
$this->attributes['title'] = $value;
149208

150209
return $this;
151210
}

tests/EditorFormOptionsTest.php

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
namespace Yajra\DataTables\Html\Tests;
4+
5+
use Yajra\DataTables\Html\Editor\FormOptions;
6+
7+
class EditorFormOptionsTest extends TestCase
8+
{
9+
/** @test */
10+
public function it_has_setters()
11+
{
12+
$options = FormOptions::make();
13+
14+
$this->assertInstanceOf(FormOptions::class, $options);
15+
16+
$options->focus(1)
17+
->message('message')
18+
->onBackground('onBackground')
19+
->onBlur('onBlur')
20+
->onComplete('onComplete')
21+
->onEsc('onEsc')
22+
->onFieldError('onFieldError')
23+
->onReturn('onReturn')
24+
->submit('submit')
25+
->title('title')
26+
->drawType('drawType')
27+
->scope('scope')
28+
->nest(false)
29+
->buttons([])
30+
->submitTrigger(1)
31+
->submitHtml('submitHtml');
32+
33+
$this->assertEquals(1, $options->focus);
34+
$this->assertEquals('message', $options->message);
35+
$this->assertEquals('onBackground', $options->onBackground);
36+
$this->assertEquals('onBlur', $options->onBlur);
37+
$this->assertEquals('onComplete', $options->onComplete);
38+
$this->assertEquals('onEsc', $options->onEsc);
39+
$this->assertEquals('onFieldError', $options->onFieldError);
40+
$this->assertEquals('onReturn', $options->onReturn);
41+
$this->assertEquals('submit', $options->submit);
42+
$this->assertEquals('title', $options->title);
43+
$this->assertEquals('drawType', $options->drawType);
44+
$this->assertEquals('scope', $options->scope);
45+
$this->assertEquals(false, $options->nest);
46+
$this->assertEquals([], $options->buttons);
47+
$this->assertEquals(1, $options->submitTrigger);
48+
$this->assertEquals('submitHtml', $options->submitHtml);
49+
}
50+
}

0 commit comments

Comments
 (0)