diff --git a/src/Components/Component.php b/src/Components/Component.php index eaaca28..bc39ec7 100644 --- a/src/Components/Component.php +++ b/src/Components/Component.php @@ -73,9 +73,19 @@ public function id(): string } if ($this->name) { - return $this->id = "auto_id_" . $this->name; + return $this->id = $this->generateIdByName(); } return $this->id = Str::random(4); } + + /** + * Generates an ID by the name attribute. + * + * @return string + */ + protected function generateIdByName(): string + { + return "auto_id_" . $this->name; + } } diff --git a/src/Components/FormCheckbox.php b/src/Components/FormCheckbox.php index d6ff839..d1fb19c 100644 --- a/src/Components/FormCheckbox.php +++ b/src/Components/FormCheckbox.php @@ -50,4 +50,14 @@ public function __construct( $this->checked = is_null($boundValue) ? $default : $boundValue; } } + + /** + * Generates an ID by the name and value attributes. + * + * @return string + */ + protected function generateIdByName(): string + { + return "auto_id_" . $this->name . "_" . $this->value; + } } diff --git a/src/Components/FormRadio.php b/src/Components/FormRadio.php index 4e3db45..b4f3c61 100644 --- a/src/Components/FormRadio.php +++ b/src/Components/FormRadio.php @@ -35,4 +35,14 @@ public function __construct( $this->checked = (is_null($boundValue) ? $default : $boundValue) == $this->value; } } + + /** + * Generates an ID by the name and value attributes. + * + * @return string + */ + protected function generateIdByName(): string + { + return "auto_id_" . $this->name . "_" . $this->value; + } }