Results 1 to 4 of 4

Thread: set default checkbox value (FE)

  1. #1
    User
    Join Date
    06-20-09.
    Posts
    64

    Default set default checkbox value (FE)

    Hi,

    I'm trying to set default value for the check-box group for frontend form, but I can't do this, the "default" parameter is ignored,
    I've tried to check this on core .

    formCheckbox.php tried to mark option as checked by this function $this->isChecked($arrOption),

    and this function check for if (empty($this->varValue) && $arrOption['default']), if it's empty it mark 1 option as default, if it set, it mark correct one.

    The problem is that there no $this->varValue by default (you can't set it in DCA), and also there are no $arrOption['default'], because if you try to add 'default' to options array - it will create option called default. if you put default to the eval() or as separated options, it will be ignored.

    logic for default values is written in the widget.php, and seems that it doesn't work for checkboxes

    this is the example of my DCA array

    Code:
    $GLOBALS['TL_DCA']['tl_member']['fields']['oktolist'] = array(
            'label'     => &$GLOBALS['TL_LANG']['tl_member']['oktolist'],
            'inputType' => 'checkbox',
           'default' => '????'
            'eval'      => array('mandatory' => false,   'default' => '????', 'tl_class' => 'w50', 'configure' => true, 'feEditable' => true ),
            'options'   => array('aaa','bbb','ccc')
    );
    if someone knew how to do this, please tell me.

  2. #2
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: set default checkbox value (FE)

    remove the defaul entry in the eval because it is useless

    take a look at backend/dca/tl_user_group.php the alpty field is a checkbox with default value set

    hope this helps
    Consulenza Contao CMS https://www.intco.it

  3. #3
    User
    Join Date
    06-20-09.
    Posts
    64

    Default Re: set default checkbox value (FE)

    Thank you ga.n for reply,
    I've checked tl_user_group.php and find some examples for default checking checkboxes.

    but it does't work for me on frontend. this is my code:

    Code:
    $GLOBALS['TL_DCA']['tl_member']['fields']['oktolist'] = array(
    'label'                   => &$GLOBALS['TL_LANG']['FOP']['fop'],
    			'exclude'                 => true,
    			'default'                 => array('f1', 'f2', 'f3'),
    			'inputType'               => 'checkbox',
    			'options'                 => array('f1', 'f2', 'f3', 'f4', 'f5'),
    			'reference'               => &$GLOBALS['TL_LANG']['FOP'],
    			'eval'                    => array('multiple'=>true, 'mandatory' => false, 'tl_class' => 'w50', 'configure' => true, 'feEditable' => true)
            );

  4. #4
    User
    Join Date
    06-20-09.
    Posts
    64

    Default Re: set default checkbox value (FE)

    This is just part tl_user_group.php, I've copied it ot my file, seems that everything works for backend, but no "right" solution for frontend. I can use JS , or try to catch and set all values on form.tpl....

    Maybe someone has another, more "contao way" solution.

    Thank you!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •