# Reusable Form Components This directory contains reusable Blade components for forms across the application. ## Available Components ### 1. Country Dropdown (``) A dropdown with country flags that stores the ISO3 country code. **Features:** - Flag icons for each country - Loads data from `/data/countries.json` - Preserves selected value on validation errors - Displays validation errors - Clean, modern UI with flag icons **Usage:** ```blade ``` **Props:** - `name` (default: 'country') - The name attribute for the select - `id` (default: 'country') - The ID for the select element - `value` (default: '') - The initial/selected value (ISO3 code) - `required` (default: false) - Whether the field is required - `error` (default: null) - Error message to display **Example in a form:** ```blade
``` --- ### 2. Call Code Dropdown (``) A dropdown with country flags and call codes that stores the call code. **Features:** - Flag icons for each country - Displays country name and call code - Loads data from `/data/countries.json` - Preserves selected value on validation errors - Displays validation errors **Usage:** ```blade ``` **Props:** - `name` (default: 'call_code') - The name attribute for the select - `id` (default: 'call_code') - The ID for the select element - `value` (default: '') - The initial/selected value (call code) - `required` (default: false) - Whether the field is required - `error` (default: null) - Error message to display **Example in a form:** ```blade
``` --- ### 3. Currency Dropdown (``) A dropdown with country flags and currency symbols that stores the currency code. **Features:** - Flag icons for each country - Displays country name, currency code, and currency symbol - Loads data from `/data/countries.json` - Preserves selected value on validation errors - Displays validation errors **Usage:** ```blade ``` **Props:** - `name` (default: 'currency') - The name attribute for the select - `id` (default: 'currency') - The ID for the select element - `value` (default: '') - The initial/selected value (currency code) - `required` (default: false) - Whether the field is required - `error` (default: null) - Error message to display **Example in a form:** ```blade
``` --- ### 4. Timezone Dropdown (``) A dropdown with country flags and timezones that stores the timezone. **Features:** - Flag icons for each country - Displays country name and timezone - Loads data from `/data/countries.json` - Preserves selected value on validation errors - Displays validation errors **Usage:** ```blade ``` **Props:** - `name` (default: 'timezone') - The name attribute for the select - `id` (default: 'timezone') - The ID for the select element - `value` (default: '') - The initial/selected value (timezone) - `required` (default: false) - Whether the field is required - `error` (default: null) - Error message to display **Example in a form:** ```blade
``` --- ## Dependencies All components require: ### Flag Icons ```html ``` ### Countries Data File All components load country data from `/public/data/countries.json` which contains: - Country name - ISO2 code (2-letter) - ISO3 code (3-letter) - Flag code (for flag-icons) - Call code (phone country code) - Currency code - Currency symbol - Timezone **Note:** Israel is excluded from the countries list as requested. --- ## Complete Example Form Here's a complete example of a form using all components: ```blade @extends('layouts.app') @section('content')

User Information

@csrf
@stack('scripts') @endsection ``` --- ## Notes 1. **Data Loading**: All components use JavaScript's `fetch()` API to load country data from `/data/countries.json`. This ensures the data is loaded asynchronously and doesn't block page rendering. 2. **Value Preservation**: All components support Laravel's `old()` helper to preserve selected values after validation errors. 3. **Validation**: All components integrate with Laravel's validation system and display error messages when validation fails. 4. **Flag Icons**: All components use the flag-icons library (v6.6.6) for displaying country flags. 5. **Multiple Instances**: You can use multiple instances of any component on the same page. Each instance will work independently. 6. **Custom Styling**: Each component includes custom CSS for flag positioning and sizing. 7. **Unique Values**: - Currency dropdown shows unique currencies (countries with same currency are grouped) - Timezone dropdown shows unique timezones (countries with same timezone are grouped) 8. **Israel Excluded**: As requested, Israel is not included in the countries.json file. --- ## Component Comparison | Component | Displays | Stores | Example Value | |-----------|----------|--------|---------------| | Country Dropdown | Flag + Country Name | ISO3 Code | USA, GBR, ARE | | Call Code Dropdown | Flag + Name + Call Code | Call Code | +1, +44, +971 | | Currency Dropdown | Flag + Name + Currency | Currency Code | USD, EUR, AED | | Timezone Dropdown | Flag + Name + Timezone | Timezone | America/New_York, Europe/London, Asia/Dubai | --- ## Troubleshooting **Flags not displaying:** - Ensure flag-icons CSS is loaded in your layout or view - Check browser console for any CSS loading errors **Dropdown not populating:** - Check that `/public/data/countries.json` exists and is accessible - Check browser console for any fetch errors - Ensure the file path is correct **Values not preserving after validation:** - Ensure you're passing the correct value to the `:value` prop - Use `old('field_name')` to get the previous value - Check that the field name matches your validation rules **Multiple instances conflicting:** - Each component uses a unique ID based on the `id` prop - Ensure each instance has a unique `id` prop value