- How do I add the calculator to a Filament resource or page?
- Use the `CalculatorAction` in your resource or page. Extend a `TextInput` field with `extraActions` and attach the calculator modal. Example: `TextInput::make('price')->extraActions([CalculatorAction::make()->label('Open Calculator')->modalWidth('50%')])`. Ensure you import the action class from `ariefng/filament-calculator`.
- Does this package support Filament v2 or only v3?
- The package is designed for **Filament v3.x** and may not work with v2 due to architectural differences in actions, modals, and field extensions. Always check the package’s release notes for version-specific requirements. If using v2, consider alternatives like custom Livewire components.
- Can I customize the calculator’s UI (buttons, operators, styling)?
- Yes, the package likely exposes methods to modify operators, labels, and modal width (e.g., `modalWidth('70%')`). For deeper styling, override CSS in your Filament theme’s `resources/css/filament` directory. Check the `CalculatorAction` class for available customization hooks.
- Will this work with custom Filament themes or Tailwind configurations?
- The calculator should adapt to your Filament theme if it uses Tailwind CSS, but test for conflicts with custom colors or spacing. For stubborn styling issues, inspect the modal’s HTML classes and override them in your theme’s CSS. Namespacing (e.g., `filament-calculator-*`) helps avoid collisions.
- Is there server-side validation for calculator inputs? Should I add it?
- The package focuses on frontend calculations, so **no server-side validation is included by default**. If your workflow requires it (e.g., preventing SQL injection in dynamic queries), add Laravel validation rules to your form or resource logic. Use `->rules()` on the `TextInput` field to enforce constraints.
- How do I handle complex calculations (e.g., financial formulas, unit conversions)?
- For simple arithmetic, the frontend calculator suffices. For complex logic, offload calculations to Laravel controllers or services and fetch results via API routes. Use the calculator to input values, then trigger a backend process via a Filament action or form submission.
- What happens if JavaScript is disabled in the browser?
- Filament modals (and thus the calculator) **require JavaScript**. If disabled, the action button will likely show a fallback or fail gracefully. For critical workflows, ensure your app communicates this dependency or provides an alternative (e.g., a separate calculation page).
- Can I use this in production for sensitive data (e.g., financial transactions)?
- The package is lightweight and safe for non-sensitive calculations, but **avoid using it for financial transactions without additional validation**. Always validate and sanitize inputs server-side, especially if calculator results influence database operations or API calls.
- Are there alternatives if I need more advanced features (e.g., graphs, history)?
- For basic calculations, this package is ideal. For advanced features, consider standalone tools like **Livewire-based calculators** or third-party libraries (e.g., MathJax for complex formulas). If you need Filament integration, explore plugins like `spatie/laravel-filament-resource-extensions` for custom actions.
- How do I test the calculator in my Laravel application?
- Test by adding the calculator to a non-critical resource first. Verify modal triggers, calculation accuracy, and form submission behavior. Use Laravel’s testing tools to simulate interactions: `browser()->click()` for buttons and `assertSee()` to check modal content. Test edge cases like large numbers or special characters.