TALL-forms
  • TALL-forms
  • Installation
    • Quickstart: Artisan cmd
    • Manual installation
      • Package
      • Translations
      • Css & Theme
      • Javascript
      • Tailwind
      • Laravel Mix
      • Wrapper view
      • Laravel Jetstream/Breeze
  • Upgrade v7 to v8
    • Configuration changes
    • Component & Field changes
    • Blade view changes
    • Notification changes
    • Styling changes
  • Concept
    • Configuration
    • Validation
    • Styling
    • Icons
    • Javascript
    • Layout vs Wrapper
    • Model binding
    • Manually saving data
    • Extend Blade Components
  • Create Forms
    • Form Data
    • Form Types
      • Standard form
      • As modal
      • Without buttons
      • Fields only
      • Headless
    • Form attributes
    • Form buttons
    • Form slots
    • Form methods
    • Lifecycle hooks
    • Render a form
    • Mass generate
  • Fields
    • Declaration
    • Labels
    • Field Slots
    • Field methods
    • Custom field attributes
    • Conditional field
    • Custom view
    • Custom field
    • Custom Livewire component
    • Relations
    • Fields
      • Checkbox
      • Checkboxes
      • FileUpload
      • Honeypot
      • ImageCropper
      • Input
      • Password
      • InputArray
      • KeyVal (array)
      • Radio
      • Range
      • Repeater (array)
      • Search
      • Select & Multiselect
      • Tags
      • TagsSearch
      • Textarea
      • Trix
      • SpatieTags
    • Sponsor Fields
      • More Inputs
      • CKEditor
      • DatePicker
      • Heading
      • Markdown
      • Panels
      • SearchList
      • SelectOptGroup
      • Tabs
      • Trix, file-uploads
  • Blade components
    • Notifications
    • Label wrapper
    • Button
    • Modal blade component
    • Modal form blade component
  • Examples
    • Input examples
    • Array fields example
Powered by GitBook
On this page

Was this helpful?

  1. Examples

Input examples

protected function fields()
{
    return [        
        $this->name(),
        $this->text(),
        $this->password(),
        $this->passwordConfirmation(),
        $this->url(),
        $this->number(),
        $this->tel(),
        $this->email(),
        $this->dateTimeLocal(),
        $this->select(),
        $this->checkbox(),
        $this->checkboxes(),
        $this->radio(),
        $this->textarea(),
        $this->range(),        
    ];
}

protected function number()
{
    return Input::make('Number')
        ->type('number')
        ->prefix('#')
        ->step(2)
        ->min(5)
        ->max(10)
        ->rules('required|integer');
}

protected function dateTimeLocal()
{
    return Input::make('Date Time Local', 'birthday')
        ->type('datetime-local')
        ->step(7)
        ->min('2020-09-15')
        ->max('2021-12-31')
        ->default(now()->toDateTimeLocalString('minute')) //or now()->format('Y-m-d\TH:i')
        ->rules('required');
}

protected function range()
{
    return Range::make('Range')
        ->default(3)
        ->min(1)
        ->max('100')
        ->step(1)
        ->rules('required|integer');
}

protected function tel()
{
    return Input::make('Phone')
        ->type('tel')
        ->prefix('phone:')
        ->placeholder('### ### ### ###')
        ->rules('required|alpha_dash');
}

protected function email()
{
    //example: set the validation based on if the model exists in optional model binding
    $email_rule = optional($this->model)->exists
        ? ['required', 'email', Rule::unique('users', 'email')->ignore($this->model->id)]
        : 'required|email|unique:users,email';
    return Input::make('Email')
        ->fieldWidth('w-full sm:max-w-sm')
        ->type('email')
        ->prefix('@')
        ->rules($email_rule);
}

protected function url()
{
    return Input::make('Url', 'url')
        ->type('url')
        ->prefix('https://')
        ->rules('required|active_url');
}

protected function text()
{
    return Input::make('Text')
        ->help('Some help text')
        ->icon('file-user')//requires blade ui kit icons
        ->rules('required|string');
}

protected function textarea()
{
    return Textarea::make('Textarea')
        ->placeholder('Tell me a story')
        ->rows(3)
        ->rules('required');
}

protected function checkbox()
{
    return Checkbox::make('Checkbox') //cast to boolean on model
        ->placeholder('The checkbox label')
        ->rules('boolean')
        ->default(1); //equivalent to checked
}

/**
 * Checkboxes, associative array
 * @return Checkboxes
 */
protected function checkboxes()
{
    $options = ['Wifi' => 'wf', 'Bluetooth' => 'bl', 'Ethernet' => 'eth'];
    return Checkboxes::make('Checkboxes')
        ->options($options)
        ->rules(['array', Rule::in(array_values($options))])
        ->default(['wf']);
}

/**
 * Radio, associative array
 * @return Radio
 */
protected function radio()
{
    $options = ['Wifi' => 'wf', 'Bluetooth' => 'bl', 'Ethernet' => 'eth'];
    return Radio::make('Radio')
        ->options($options)
        ->rules([Rule::in(array_values($options))])
        ->default('wf');
}

protected function select()
{
    $options = Brand::pluck('id', 'name')->toArray();
    return Select::make('Brand', 'brand_id')
        ->options($options)
        ->placeholder('Please select a brand.')
        ->rules(['nullable', Rule::in(array_values($options))]);
}

protected function name()
{
    return Input::make('Name')
        ->rules([
            'required', 
            Rule::unique('cars', 'name')->ignore($this->model->id)
    ]);
}

protected function password()
{
    return Input::make('Password')
        ->type('password')
        ->rules('required|alpha_dash|min:8');
}

protected function passwordConfirmation()
{
    return Input::make('Repeat password', 'password_confirmation')
        ->type('password')
        ->custom()
        ->rules('required|same:form_data.password');
}
PreviousModal form blade componentNextArray fields example

Last updated 3 years ago

Was this helpful?