Okay
  Public Ticket #3030045
Choose a Author to default
Closed

Comments

  • Xuân An started the conversation

    Hi Admin,

    I have array author

    array (size=6)  39 => string 'Hữu Hồng Minh Nguyễn' (length=26)  40 => string 'Nguyệt Minh Lê' (length=17)  41 => string 'Thị Ngọc Mai Trần' (length=23)  42 => string 'Hoàng Anh Châu Nguyễn' (length=25)  43 => string 'Sơn Trà Nguyễn' (length=18)  77 => string 'System Admin' (length=12)

    I would like choose id= 40 to default.

    I find source code show authors and I edit but it do not effect.

    $form
                    ->setValidatorClass(CustomPostRequest::class)
                    ->addAfter('status', 'author_id', 'customSelect', [
                        'label'      => __('Author'),
                        'label_attr' => ['class' => 'control-label required'],
                        'attr'       => [
                            'placeholder' => __('Select an author...'),
                        ],
                        'choices'    => $authorsArray,
                    ]);

    Please help me edit it.

    Thanks!


  •  252
    The replied

    Hi,
    You just need to add
    'default value' => $defaultValue

    $form
                    ->setValidatorClass(CustomPostRequest::class)
                    ->addAfter('status', 'author_id', 'customSelect', [
                        'label'      => __('Author'),
                        'label_attr' => ['class' => 'control-label required'],
                        'attr'       => [
                            'placeholder' => __('Select an author...'),
                        ],
                        'choices'    => $authorsArray,
                        'default value' => $defaultValue
                    ]);
    
  • Xuân An replied

    Hi admin,

    I add some case but not effect

    'default value' => '40'
    'default value' => 'Nguyệt Minh Lê'

    or

     $b = new ArrayObject();                                  
     $b['40'] = 'Nguyệt Lê Minh';

    'default value' => $b


    Thanks!



  •  252
    The replied

    Hi Xuan An,

    We typed it wrong. Exactly like the attached picture.

    2796994540.png