F
F
FernandoErrNando2017-01-12 11:34:50
Yii
FernandoErrNando, 2017-01-12 11:34:50

Yii2 how to properly internationalize DateControl/DatePicker when working with RenderAjax or correct parameter passing?

Dear colleagues. There is a problem:
1. There is a page on which a form is called in a modal window after clicking the button. The form contains a field for entering dates with a DateControl (or DatePicker, in this case, it doesn't matter) component.
Problem: When you click on the button, the page with the form is loaded into the modal window, but the DatePicker in the loaded form is not Russified.
When calling the page directly - datePicker with the correct regional settings (i.e. the first day is Monday, Russified, etc.).
What am I doing wrong? In theory, the renderAjax() method should render the plug-in view with all styles/scripts per request, but I have a feeling that this does not happen, or some parameters of the
Controller are lost:

public function actionIndex()
{
...
}

public function actionCreatemodalsuperform()
    {
        $model = new mysuperForm();
        $post=\Yii::$app->request->post();
        if ($post) 
        {
           ...
        }
        else {
                return $this->renderAjax('createmodalsuperform', [
                    'model' => $model,
                ]);
            }
    }


Form call page via Ajax
views\index.php
...
$this->registerJs('
$(function(){
    $("#createModalSuperformButton").click(function(){
        $("#createNewModalSuperform").modal("show").find("#modalSuperform").load($(this).attr("value"));
    });
});
', yii\web\View::POS_END);
?>
...
 <?= Html::button('<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>',
       [
        'value'=>Url::to('/fund/createsuperform'),
       'class' => 'btn buttonaddfund btn-earning text-center buttonblock',
       'id' => 'createModalSuperformButton'
       ]) ?>
                
                <?php
                    Modal::begin([
                     'id' => 'createNewFundEarningModal',
                     'size'=>'modal-xs',
                    ]);
                    echo "<div id='modalContentEarning'></div>";
                    Modal::end();
                ?>

Form Page
views\createmodalsuperform.php
  <?php
...
use yii\widgets\ActiveForm;
use kartik\datecontrol\DateControl;

?> 

<div class="super-form">

    <?php $form = ActiveForm::begin( ['options' => ['enctype' => 'multipart/form-data']]); ?>
....
        <?= $form->field($model, 'date_created')->widget(FixedDateControl::classname(), [
        'type'=>DateControl::FORMAT_DATE,
        'ajaxConversion'=>true, 
        'language' => 'ru',

        'options' => [
            'class' => 'pull-right',
            'pluginOptions' => [
                'autoclose' => true,

            ],
            'removeButton' => false,
        ],
        'saveTimezone' => 'UTC',
        'displayTimezone' => 'UTC',

        ])->label(false);?>
....    
    <?php ActiveForm::end(); ?>

</div>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question