Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing handling of required for field types #1853

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/Dropdown.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
)
)
->when(filled($attribute->validation_rules), fn (Select $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
{
return FileUpload::make($attribute->handle)
->when(filled($attribute->validation_rules), fn (FileUpload $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));
}
}
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/ListField.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
return $state;
})
->when(filled($attribute->validation_rules), fn (KeyValue $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));
}
}
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
$input = TextInput::make($attribute->handle)
->numeric()
->when(filled($attribute->validation_rules), fn (TextInput $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));

if ($min) {
Expand Down
4 changes: 2 additions & 2 deletions packages/admin/src/Support/FieldTypes/TextField.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public static function getFilamentComponent(Attribute $attribute): Component
if ($attribute->configuration->get('richtext')) {
return RichEditor::make($attribute->handle)
->when(filled($attribute->validation_rules), fn (RichEditor $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));
}

return TextInput::make($attribute->handle)
->when(filled($attribute->validation_rules), fn (TextInput $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));
}
}
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/Toggle.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ public static function getFilamentComponent(Attribute $attribute): Component
->default(false)
->when(filled($attribute->validation_rules), fn (Toggle $component) => $component->rules($attribute->validation_rules))
->rule('boolean')
->required((bool) $attribute->configuration->get('required'));
->required((bool) $attribute->required);
}
}
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/TranslatedText.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
return TranslatedTextComponent::make($attribute->handle)
->optionRichtext((bool) $attribute->configuration->get('richtext'))
->when(filled($attribute->validation_rules), fn (TranslatedTextComponent $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText($attribute->translate('description'));
}
}
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/Vimeo.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
return VimeoInput::make($attribute->handle)
->live(debounce: 200)
->when(filled($attribute->validation_rules), fn (VimeoInput $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText(
$attribute->translate('description') ?? __('lunarpanel::components.forms.youtube.helperText')
);
Expand Down
2 changes: 1 addition & 1 deletion packages/admin/src/Support/FieldTypes/YouTube.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function getFilamentComponent(Attribute $attribute): Component
return YouTubeInput::make($attribute->handle)
->live(debounce: 200)
->when(filled($attribute->validation_rules), fn (YouTubeInput $component) => $component->rules($attribute->validation_rules))
->required((bool) $attribute->configuration->get('required'))
->required((bool) $attribute->required)
->helperText(
$attribute->translate('description') ?? __('lunarpanel::components.forms.youtube.helperText')
);
Expand Down