Skip to content

Commit 10c6798

Browse files
authored
Merge pull request #114 from om3rcitak/4.0
Improve adding custom action to buttons.
2 parents 6b1bac3 + 2abe751 commit 10c6798

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Html/Button.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ public function exportOptions($value)
172172
*/
173173
public function actionSubmit()
174174
{
175-
return $this->action('function() { this.submit(); }');
175+
$this->attributes['action'] = 'function() { this.submit(); }';
176+
177+
return $this;
176178
}
177179

178180
/**
@@ -183,7 +185,11 @@ public function actionSubmit()
183185
*/
184186
public function action($value)
185187
{
186-
$this->attributes['action'] = $value;
188+
if (substring($value, 0, 8) == 'function') {
189+
$this->attributes['action'] = $value;
190+
} else {
191+
$this->attributes['action'] = "function(e, dt, node, config) { $value }";
192+
}
187193

188194
return $this;
189195
}
@@ -196,7 +202,9 @@ public function action($value)
196202
*/
197203
public function actionHandler($action)
198204
{
199-
return $this->action("function() { this.submit(null, null, function(data) { data.action = '{$action}'; return data; }) }");
205+
$this->attributes['action'] = "function() { this.submit(null, null, function(data) { data.action = '{$action}'; return data; }) }";
206+
207+
return $this;
200208
}
201209

202210
/**
@@ -206,6 +214,8 @@ public function actionHandler($action)
206214
*/
207215
public function actionClose()
208216
{
209-
return $this->action('function() { this.close(); }');
217+
$this->attributes['action'] = 'function() { this.close(); }';
218+
219+
return $this;
210220
}
211221
}

0 commit comments

Comments
 (0)