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

Commit

Permalink
Fix for #42 (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet authored Jan 4, 2021
1 parent 242e3b7 commit 76ac5d7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/Components/Component.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions src/Components/FormCheckbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
10 changes: 10 additions & 0 deletions src/Components/FormRadio.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 76ac5d7

Please sign in to comment.