Skip to content
This repository was archived by the owner on Jan 2, 2024. It is now read-only.

Commit 76ac5d7

Browse files
authored
Fix for #42 (#43)
1 parent 242e3b7 commit 76ac5d7

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/Components/Component.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,19 @@ public function id(): string
7373
}
7474

7575
if ($this->name) {
76-
return $this->id = "auto_id_" . $this->name;
76+
return $this->id = $this->generateIdByName();
7777
}
7878

7979
return $this->id = Str::random(4);
8080
}
81+
82+
/**
83+
* Generates an ID by the name attribute.
84+
*
85+
* @return string
86+
*/
87+
protected function generateIdByName(): string
88+
{
89+
return "auto_id_" . $this->name;
90+
}
8191
}

src/Components/FormCheckbox.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,14 @@ public function __construct(
5050
$this->checked = is_null($boundValue) ? $default : $boundValue;
5151
}
5252
}
53+
54+
/**
55+
* Generates an ID by the name and value attributes.
56+
*
57+
* @return string
58+
*/
59+
protected function generateIdByName(): string
60+
{
61+
return "auto_id_" . $this->name . "_" . $this->value;
62+
}
5363
}

src/Components/FormRadio.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ public function __construct(
3535
$this->checked = (is_null($boundValue) ? $default : $boundValue) == $this->value;
3636
}
3737
}
38+
39+
/**
40+
* Generates an ID by the name and value attributes.
41+
*
42+
* @return string
43+
*/
44+
protected function generateIdByName(): string
45+
{
46+
return "auto_id_" . $this->name . "_" . $this->value;
47+
}
3848
}

0 commit comments

Comments
 (0)