Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 Form builder Custom Fields Macro

Im trying to create a custom HTML 5 date field for using in a laravel 4 framework view.

{{
    Form::macro('datetime', function($field_name)
    { 
        return '';
    });         
}}

{{ Form::label('event_start', 'Event Date', array('class' => 'control-label')) }}
{{ Form::datetime('event_start') }}

The only problem is the value is not being populated, and i do not know how to do this.

Im using this form to create and edit a model called Event.

how can i populate the value of this field?

like image 457
AndrewMcLagan Avatar asked Nov 29 '22 02:11

AndrewMcLagan


1 Answers

I added in app/start/global.php the following:

Form::macro('date', function($name, $value = null, $options = array()) {
    $input =  '<input type="date" name="' . $name . '" value="' . $value . '"';

    foreach ($options as $key => $value) {
        $input .= ' ' . $key . '="' . $value . '"';
    }

    $input .= '>';

    return $input;
});

But the "good way" would be to extend the Form class and implement your methods.

like image 131
Rafa Gómez Casas Avatar answered Dec 01 '22 07:12

Rafa Gómez Casas