Skip to content

Commit

Permalink
Added a Input of type password to the CustomFormField possibilities a…
Browse files Browse the repository at this point in the history
…nd added an example use in the readme.
  • Loading branch information
ejjaquet-ch committed Aug 15, 2024
1 parent 4f59a5b commit cb44d0f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
21 changes: 14 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,15 @@ return [
'rules' => 'required|string|max:255',
],
'custom_field_2' => [
'type' => 'password',
'label' => 'Custom Password field 2',
'placeholder' => 'Custom Password Field 2',
'required' => true,
'rules' => 'required|string|max:255',
],
'custom_field_3' => [
'type' => 'select',
'label' => 'Custom Select 2',
'label' => 'Custom Select 3',
'placeholder' => 'Select',
'required' => true,
'options' => [
Expand All @@ -298,22 +305,22 @@ return [
'option_3' => 'Option 3',
],
],
'custom_field_3' => [
'custom_field_4' => [
'type' =>'textarea',
'label' => 'Custom Textarea 3',
'label' => 'Custom Textarea 4',
'placeholder' => 'Textarea',
'rows' => '3',
'required' => true,
],
'custom_field_4' => [
'custom_field_5' => [
'type' => 'datetime',
'label' => 'Custom Datetime 4',
'label' => 'Custom Datetime 5',
'placeholder' => 'Datetime',
'seconds' => false,
],
'custom_field_5' => [
'custom_field_6' => [
'type' => 'boolean',
'label' => 'Custom Boolean 5',
'label' => 'Custom Boolean 6',
'placeholder' => 'Boolean'
],
]
Expand Down
12 changes: 12 additions & 0 deletions src/Livewire/CustomFieldsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ private static function createField(string $fieldKey, array $field): ?Forms\Comp
switch ($field['type']) {
case 'text':
return self::createTextInput($fieldKey, $field);
case 'password':
return self::createPasswordInput($fieldKey, $field);
case 'boolean':
return self::createCheckbox($fieldKey, $field);
case 'select':
Expand All @@ -81,6 +83,16 @@ private static function createTextInput(string $fieldKey, array $field): TextInp
->rules($field['rules']);
}

private static function createPasswordInput(string $fieldKey, array $field): TextInput
{
return TextInput::make($fieldKey)
->label(__($field['label']))
->placeholder(__($field['placeholder']))
->required($field['required'])
->password()
->rules($field['rules']);
}

private static function createCheckbox(string $fieldKey, array $field): Checkbox
{
return Checkbox::make($fieldKey)
Expand Down

0 comments on commit cb44d0f

Please sign in to comment.