yii2 render remaining character in form field - yii2

I use jlorente remainingcharacters widget to show remaining character countdown for Inputfield in _form.php:
<?= $form->field($model, 'char52', ['showLabels'=>true])->widget(\jlorente\remainingcharacters\RemainingCharacters::classname(), [
'type' => \jlorente\remainingcharacters\RemainingCharacters::INPUT_TEXTAREA,
'text' => Yii::t('app', '{n} characters remaining'),
'label' => [
'tag' => 'p',
'id' => 'my-counter',
'class' => 'counter',
'invalidClass' => 'error'
],
'options' => [
'rows' => '1',
'class' => 'col-md-12',
'maxlength' => 52,
'placeholder' => Yii::t('app', 'Write something')
]
]) ?>
<?= $form->field($model, 'text', ['showLabels'=>true])->widget(\dosamigos\ckeditor\CKEditor::className(), [
'options' => ['rows' => 1],
'preset' => 'full'
]) ?>
As I rendered form fields the height of textInput is not the same as standard.
Is there any solution for this problem.
I am also searching for other widgets for remaining charachters as I want to use kartik\form\ActiveForm for rendering on the same text input remaining charachter count and ActiveField Prepend Addon.

Try adding "form-control" class to your widget:
'options' => [
...
'class' => 'col-md-12 form-control',
...
]

Related

Yii2 - How to remove blank space from Gridview Filter

I have this gridview
I want to replace the blank space on the status with All, so that it will have All, Active, Inactive
View:Gridview
[
'class' => '\pheme\grid\ToggleColumn',
'contentOptions' => ['class' => 'text-center'],
'attribute'=>'is_status',
'enableAjax' => false,
'filter'=>['1'=>'InActive', '0'=>'Active'],
],
How do I achieve this?
Use filterInputOptions
[
'class' => '\pheme\grid\ToggleColumn',
'contentOptions' => ['class' => 'text-center'],
'attribute' => 'is_status',
'enableAjax' => false,
'filter' => ['1' => 'InActive', '0' => 'Active'],
'filterInputOptions' => ['class' => 'form-control', 'id' => null, 'prompt' => 'All'],
],

How to make a placeholder in a listBox

It is necessary that in the field listBoxt, there was a placeholder, something like "Select a role for the user", i.e. message that the user sees without selecting anything in the listbox. But this should include the option 'prompt' => 'remove the role' so that the user can remove the role through the drop-down list.
Is it possible to do this through the standard Yii functional without resorting to JS?
echo $form->field($model, 'additionalRoles', [
'options' => [
'class' => 'form-group',
],
])->listBox($additionalRoles, [
'class' => 'form-control j-multi-select2',
'prompt' => 'Select additional role',
]);
For example: https://jsfiddle.net/8e7avn2d/1/
<?=
$form->field($model, 'additionalRoles', [
'options' => [
'class' => 'form-group',
],
])
->listBox($additionalRoles, [
'class' => 'form-control j-multi-select2',
'prompt' => [
'text' => "Select additional role",
'options' => [
'disabled' => true,
'selected' => true,
'hidden' => true,
]]
]);
?>
to achieve your example you should use dropDownList instead of listBox
echo $form->field($model, 'additionalRoles', [
'options' => [
'class' => 'form-group',
],
])->dropDownList($additionalRoles, [
'class' => 'form-control j-multi-select2',
'prompt' => 'Select additional role',
]);

Hide historical dropdown selected value in Yii2 DatePicker widget

How to hide history dropdown list in Yii2 kartik select2?
This is my source code:
<div class="col-sm-offset-2 col-sm-10" style="margin-left:135px;margin-bottom:15px">
<label class="control-label">Range Perjalanan Dinas</label>
<?= DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'model' => $model,
'attribute' => 'tgl_mulai',
'attribute2' => 'tgl_selesai',
'options' => ['placeholder' => 'Start date'],
'options2' => ['placeholder' => 'End date'],
'form' => $form,
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'autoclose' => true,
]
]); ?>
</div>
Try 'autocomplete' => 'off' in your date picker options:
<?= DatePicker::widget([
'type' => DatePicker::TYPE_RANGE,
'model' => $model,
'attribute' => 'tgl_mulai',
'attribute2' => 'tgl_selesai',
'options' => ['placeholder' => 'Start date','autocomplete' => 'off'],
'options2' => ['placeholder' => 'End date'],
'form' => $form,
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'autoclose' => true,
]
]); ?>
You may have to turn off the autocomplete in your form element
Turning off form autocomplete

Kartiv yii2 datepicker with model and custom id

I am using kartik datepicker extension http://demos.krajee.com/widget-details/datepicker in Yii2.
Issue :
If I use this with custom id for input it does not show show model validations
echo kartik\date\DatePicker::widget([
'model' => $objPatientModel,
'form'=>$objActiveForm,
'attribute' => 'date_of_birth',
'options' => ['placeholder' => 'Enter birth date ...', 'id' => 'patient_dob'], **// with id clientside validations for model does not work**
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'endDate' => date('d-m-Y'),
]
]);
While below code works
echo kartik\date\DatePicker::widget([
'model' => $objPatientModel,
'form'=>$objActiveForm,
'attribute' => 'date_of_birth',
'options' => ['placeholder' => 'Enter birth date ...'],**//id is not used here**
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'endDate' => date('d-m-Y'),
]
]);
But I want to use custom id .Any suggestions ?
You have to override the selectors, example:
$form->field($model, 'comment', ['selectors' => ['input' => '#myCustomId']])
->textarea(['id' => 'myCustomId']);?>
See https://github.com/yiisoft/yii2/issues/7627
<?=
$form->field($model, 'sales_date')->widget(DateControl::classname(), [
'name' => 'sales_date',
'value' => date('d-m-Y h:i:s'),
'type' => DateControl::FORMAT_DATETIME,
'autoWidget' => true,
'displayFormat' => 'php:d-m-Y h:i:s',
'saveFormat' => 'php:Y-m-d h:i:s',
'saveOptions' => [
'type' => 'hidden',
'form' => 'sales-form-red',
],
])
?>
by using the following option you can add extra form tag to input
'saveOptions' => [
'type' => 'hidden',
'form' => 'sales-form-red',
'class' => 'sales_date',
]
In my case out was
<input type="hidden" id="sales-sales_date" name="Sales[sales_date]" form="sales-form-red">
check by using link
Date Control Demo

Yii2-editable-widget. Doesn't work with few widgets

I'm using editable widget (2amigos/yii2-editable-widget or kartik-v/yii2-editable). It works fine, but when I try it in foreach it works with first element only. I want to use a several widgets for a model. How can I solve it?
Here is the code:
foreach ($models as $model) {
echo Editable::widget( [
'model' => $model,
'attribute' => 'name',
'url' => 'site/rename',
'type' => 'text',
'mode' => 'pop',
'clientOptions' => [
' pk' => $model->id,
]
]);
}
I guess you have to set a unique id for each Editable Widget. Look how the js code for the widget is embedded.
e.g. if you use kartiks widget
echo Editable::widget([
'model' => $model,
'attribute' => 'name',
'type' => 'primary',
'size'=> 'lg',
'inputType' => Editable::INPUT_TEXT,
'editableValueOptions' => ['class' => 'text-success h3'],
'options'=> [
'id'=>'name-editable'.uniqid(),
]
]);