An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor: replace random ID generation with Cuid2 for unique HTML IDs in form components
Andras Bacsaid2a334df781d
diff --git a/app/View/Components/Forms/Checkbox.php b/app/View/Components/Forms/Checkbox.phpindex a759164fbb..eb38d84af2 100644--- a/app/View/Components/Forms/Checkbox.php+++ b/app/View/Components/Forms/Checkbox.php@@ -6,6 +6,7 @@ use Closure;use Illuminate\Contracts\View\View;use Illuminate\Support\Facades\Gate;use Illuminate\View\Component;+use Visus\Cuid2\Cuid2;class Checkbox extends Component{@@ -57,7 +58,7 @@ class Checkbox extends Component// Generate unique HTML ID by adding random suffix// This prevents duplicate IDs when multiple forms are on the same pageif ($this->id) {- $uniqueSuffix = substr(md5(uniqid((string) mt_rand(), true)), 0, 8);+ $uniqueSuffix = new Cuid2;$this->htmlId = $this->id.'-'.$uniqueSuffix;} else {$this->htmlId = $this->id;diff --git a/app/View/Components/Forms/Datalist.php b/app/View/Components/Forms/Datalist.phpindex 08a320f687..3b7a9ee348 100644--- a/app/View/Components/Forms/Datalist.php+++ b/app/View/Components/Forms/Datalist.php@@ -64,7 +64,7 @@ class Datalist extends Component// This prevents duplicate IDs when multiple forms are on the same pageif ($this->modelBinding && $this->modelBinding !== 'null') {// Use original ID with random suffix for uniqueness- $uniqueSuffix = substr(md5(uniqid((string) mt_rand(), true)), 0, 8);+ $uniqueSuffix = new Cuid2;$this->htmlId = $this->modelBinding.'-'.$uniqueSuffix;} else {$this->htmlId = (string) $this->id;diff --git a/app/View/Components/Forms/Input.php b/app/View/Components/Forms/Input.phpindex 9a0c87c0ab..5ed347f423 100644--- a/app/View/Components/Forms/Input.php+++ b/app/View/Components/Forms/Input.php@@ -55,12 +55,11 @@ class Input extends Component// Don't create wire:model binding for auto-generated IDs$this->modelBinding = 'null';}-// Generate unique HTML ID by adding random suffix// This prevents duplicate IDs when multiple forms are on the same pageif ($this->modelBinding && $this->modelBinding !== 'null') {// Use original ID with random suffix for uniqueness- $uniqueSuffix = substr(md5(uniqid((string) mt_rand(), true)), 0, 8);+ $uniqueSuffix = new Cuid2;$this->htmlId = $this->modelBinding.'-'.$uniqueSuffix;} else {$this->htmlId = (string) $this->id;diff --git a/app/View/Components/Forms/Select.php b/app/View/Components/Forms/Select.phpindex 54d83ded74..026e3ba8c7 100644--- a/app/View/Components/Forms/Select.php+++ b/app/View/Components/Forms/Select.php@@ -57,7 +57,7 @@ class Select extends Component// This prevents duplicate IDs when multiple forms are on the same pageif ($this->modelBinding && $this->modelBinding !== 'null') {// Use original ID with random suffix for uniqueness- $uniqueSuffix = substr(md5(uniqid((string) mt_rand(), true)), 0, 8);+ $uniqueSuffix = new Cuid2;$this->htmlId = $this->modelBinding.'-'.$uniqueSuffix;} else {$this->htmlId = (string) $this->id;diff --git a/app/View/Components/Forms/Textarea.php b/app/View/Components/Forms/Textarea.phpindex 9b91bc5a0b..a5303b9473 100644--- a/app/View/Components/Forms/Textarea.php+++ b/app/View/Components/Forms/Textarea.php@@ -71,7 +71,7 @@ class Textarea extends Component// This prevents duplicate IDs when multiple forms are on the same pageif ($this->modelBinding && $this->modelBinding !== 'null') {// Use original ID with random suffix for uniqueness- $uniqueSuffix = substr(md5(uniqid((string) mt_rand(), true)), 0, 8);+ $uniqueSuffix = new Cuid2;$this->htmlId = $this->modelBinding.'-'.$uniqueSuffix;} else {$this->htmlId = (string) $this->id;