Repeatable field in simple module

edited November 2015 in Modules
Hi to all
I'm create simple module named events, that must display page with text, google map, date start, date end and image galery.
And I'm try to create field for image galery with repeatable ability (like in layouts with properhy 'repeatable' => TRUE).
How can I do this?
Sorry for my bad english.

Comments

  • edited 5:45PM
    Hi!
    I used the field "template" with params - 'repeatable' => true, for such purposes.
  • edited 5:45PM
    Thank you for answer, but I cant't find how to use it in Simple Module.
    Where to write a layout parameters in it?
  • edited 5:45PM
    I found where to use repeatable parameter, but get another problem.
    When I save data in admin panel in my Events model, nothing go to the database.
    I'm use fuel cms version 1.3
    Here database field to store image galery:
    'slider_image' text NOT NULL
    And Events_model class:

    class Events_model extends Base_module_model {

    public $serialized_fields = array('slider_image');

    function __construct() {
    parent::__construct('events');
    }

    function form_fields($values = array(), $related = array()) {
    $fields = parent::form_fields($values, $related);

    $fields['slider_image'] = array(
    'display_label' => TRUE,
    'type' => 'template',
    'repeatable' => TRUE,
    'label' => 'Images Galery',
    'name' => 'galery',
    'fields' =>
    array(
    'image' => array('type' => 'image')
    )
    );

    return $fields;
    }

    }

    All other fields like title, date, text save normaly, problem only with slider_image repeatable field.

    Please help me to solve this problem with store repeatable field in database.
  • edited 5:45PM
    You need to remove the line:
    'name' => 'galery',
  • edited 5:45PM
    I do that and repeatable field becomes simple input field.
    Please tell me what do I do wrong?
  • edited 5:45PM
    I solve this problem.
    The problem was that it is impossible to name a repeatable field came to an end in an _image or _img
    And thanks to Andrew, if don't remove 'name' property data don't save to database.
  • edited 5:45PM
    I spend 2 days to find out why my code wasn't working. And nowhere its writen that repeatable field can't end with 'image', it would be great if you could idicate it somewhere in your User Guide.
  • edited 5:45PM
    Actually, there is no such field type, like 'image'
    you can use 'type' => 'asset' for this purpose

    but if you strongly want to use type 'image',
    you you can define it in /fuel/modules/fuel/config/custom_fields.php
    // Asset field $fields['asset'] = array( 'class' => array(FUEL_FOLDER => 'Fuel_custom_fields'), 'function' => 'asset', 'filepath' => '', 'js_function' => 'fuel.fields.asset_field', 'represents' => array('name' => '.*image\]?$|.*img\]?$', 'type' => 'image'), );
  • edited 5:45PM
    The template field type will post an array syntax of:
    $slide_image[0]['image'] = 'my_image1.jpg'; $slide_image[1]['image'] = 'my_image2.jpg' $slide_image[02]['image'] = 'my_image3.jpg'
    Because it is this nested array syntax, the data needs to be serialized or handled with a mode
Sign In or Register to comment.