Button.php 648 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace Dcat\Admin\Form\Field;
  3. use Dcat\Admin\Form\Field;
  4. use Illuminate\Support\Str;
  5. class Button extends Field
  6. {
  7. protected $class = 'btn-primary';
  8. public function __construct($label)
  9. {
  10. parent::__construct(Str::random(), [$label]);
  11. $this->addVariables(['buttonClass' => $this->class]);
  12. }
  13. public function class(string $class)
  14. {
  15. return $this->addVariables(['buttonClass' => $class]);
  16. }
  17. public function on($event, $callback)
  18. {
  19. $this->script = <<<JS
  20. $('{$this->getElementClassSelector()}').on('$event', function() {
  21. $callback
  22. });
  23. JS;
  24. return $this;
  25. }
  26. }