Form builder

edited June 2017 in Modules
Hi. I'm building a form using form_builder class and I need this date picker field. I use the same code as is given in the example here: http://docs.getfuelcms.com/general/forms#date

No date picker appear :(

Controller:
public function index()
{
// load Form_builder;
$this->load->library('form_builder');

// load the custom form fields
$this->form_builder->load_custom_fields(APPPATH.'config/custom_fields.php');

// create fields
$fields['linked'] = array('type' => 'linked', 'linked_to' => array('name' => 'url_title'));
$fields['datetime'] = array('type' => 'datetime', 'first_day' => 2, 'date_format' => 'dd-mm-yyyy', 'min_date' => '01-01-2012', 'max_date' => '31-12-2012');
$fields['test_image'] = array('upload' => TRUE);
$fields['number'] = array('type' => 'number', 'represents' => 'int|smallint|mediumint|bigint', 'negative' => TRUE, 'decimal' => TRUE);
$fields['currency'] = array('type' => 'currency', 'negative' => TRUE, 'decimal' => '.');
$fields['phone'] = array('type' => 'phone', 'required' => TRUE);
$fields['file_example'] = array('type' => 'file', 'overwrite' => TRUE, 'display_overwrite' => TRUE, 'multiple' => FALSE);
$fields['state'] = array('type' => 'state');
$fields['list_items'] = array('type' => 'wysiwyg', 'editor' => 'markitup');
$fields['date_example'] = array('type' => 'date', 'first_day' => 2, 'date_format' => 'd-m-Y', 'min_date' => '01-01-2012', 'max_date' => '31-12-2012');

// set the fields
$this->form_builder->set_fields($fields);

// render the page
$vars['form'] = $this->form_builder->render();
$this->load->view('test', $vars);

}

View file:

" rel="stylesheet" type="text/css" media="all" />



<?=$form?>

">


Comments

  • edited 5:57AM
    Well, in view file I load jQuery from here https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js and bootstrap.min.js in header part and then in body this $form variable.
    What's wrong with it?
  • edited 5:57AM
    It sounds like you are building this form for the front-end of your forms. There is a fuel/modules/fuel/assets/js/fuel/custom_fields.js that has the initialization function of fuel.fields.datetime_field that will also need to be loaded. You can also try adding this line:
    $this->form_builder->load_custom_fields(APPPATH.'config/custom_fields.php');
  • edited 5:57AM
    Thanks for support and for the fast answer! Well, yeah, I do include this line, it's right after form_builder initialization. I've been testing with wysiwyg field type and the editor is not loaded either. So I guess the problem is with the js initialization? There are no js errors on the console. I guess I'll take a closer look tomorrow
  • edited 5:57AM
    I got it. In my case bootstrap-datepicker component was not included. After I included it (">) the problem was solved. I think there's some amount of css needs to be added but that's a little pain.
    I was confident all needed components are loaded automatically.
Sign In or Register to comment.