InputGroup.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Sections;
  3. use ModulesGarden\ProxmoxAddon\Core\UI\Traits\Description;
  4. use \ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Fields\InputGroupElements;
  5. use \ModulesGarden\ProxmoxAddon\Core\UI\Widget\Forms\Validators\BaseValidator;
  6. /**
  7. * InputGroup section controler
  8. *
  9. * @author Sławomir Miśkowicz <slawomir@modulesgarden.com>
  10. */
  11. class InputGroup extends BaseSection
  12. {
  13. use Description;
  14. protected $id = 'inputGroup';
  15. protected $name = 'inputGroup';
  16. public function __construct($baseId = null)
  17. {
  18. parent::__construct($baseId);
  19. $this->description = null;
  20. }
  21. public function addInputComponent($component)
  22. {
  23. $this->addField($component);
  24. return $this;
  25. }
  26. public function addTextField($initName, $placecholder = false, $notEmpty = true, BaseValidator $validator = null)
  27. {
  28. $newTextField = new InputGroupElements\Text($initName);
  29. if ($notEmpty && !$validator)
  30. {
  31. $newTextField->notEmpty();
  32. }
  33. else
  34. {
  35. $newTextField->addValidator($validator);
  36. }
  37. if ($placecholder)
  38. {
  39. $newTextField->setPlaceholder($placecholder);
  40. }
  41. $this->addInputComponent($newTextField);
  42. return $this;
  43. }
  44. public function addInputAddon($initName, $title = false, $rawTitle = false)
  45. {
  46. $newAddonField = new InputGroupElements\InputAddon();
  47. $newAddonField->setName($initName);
  48. if ($title)
  49. {
  50. $newAddonField->setTitle($title);
  51. }
  52. if ($rawTitle)
  53. {
  54. $newAddonField->setRawTitle($rawTitle);
  55. }
  56. $this->addInputComponent($newAddonField);
  57. return $this;
  58. }
  59. }