Required =>true, mandatory=>true not working for calendar

hi,
at first happy new year 2020 :slight_smile:

i am using addfield with calendar to create a new line . The calender filed must be filled
i think that i should use the attribute required=>true or mandatory=>true . but it does not work.
did i some mistake ?

 $ls_stock_form = $this->app->add('Form', [
        'segment'
    ]);
    $ls_stock_sub_layout = $ls_stock_form->layout->addSubLayout('Generic');
    $ls_stock_sub_layout->add([
        'Header',
        'Bestand'
    ]);

    $ls_stock_sub_layout->addField('sku');
    $ls_stock_sub_layout->addField('ref_date', [
        'Calendar',
        'required' => true,
        'mandatory' => true,
        'type' => 'date',
        'caption' => 'Stichtag'
    ]);

BR
Peter

form’s addField takes 3 arguments:

  1. name
  2. decorator definition
  3. field definition.

You’re passing “mandatory” to decorator definition. It looks at the ‘ref_date’ of a model associated with the form and checks required/mandatory flags there. Since you’re not using the model, you can inject data field defintiion as 3rd argument like this:

$form->addField('ref_date', ['Calendar'],  ['mandatory'=>true]);

Data field specific arguments go in 3rd argument as for the 2nd argument you can configure your decorator parameters such as what is the earliest or latest date to show on the calendar - through options (https://github.com/atk4/ui/blob/develop/src/FormField/Calendar.php#L30)

Hi Romaninsh,
Happy new year :slight_smile:
Thanks for your explain. That’s my problem. I don’t know where to find the documentation. I read currently only https://agile-ui.readthedocs.io/en/latest/. Or are there another links? or should inline documentaiton of coding better ?
BR
Peter