Editable row with number type - yii2

How can i make this input type with number. I mean when the page is opened in mobile phone, it'll be open the number keyboard.
[
'class'=>'kartik\grid\EditableColumn',
'headerOptions' => ['style' => 'width:10%', 'class'=>'text-center'],
'editableOptions'=>[
'asPopover' => false,
'inputType'=>\kartik\editable\Editable::INPUT_TEXT,
// Change here:
'editableValueOptions'=>['type'=>'number']
],
'attribute'=>'quantity',
'label'=>'Quantity',
],
EDIT ->> add 'editableValueOptions'=>['type'=>'number']

Use editableValueOptions. As the documentation says:
editableValueOptions: array, the HTML attributes for the editable value displayed.
[
'class'=>'kartik\grid\EditableColumn',
'headerOptions' => ['style' => 'width:10%', 'class'=>'text-center'],
'editableOptions'=>[
'asPopover' => false,
'inputType'=>\kartik\editable\Editable::INPUT_TEXT,
// Change here:
'editableValueOptions'=>['type'=>'number']
],
'attribute'=>'quantity',
'label'=>'Quantity',
],

'attribute' => 'quantity',
'class' => 'kartik\grid\EditableColumn',
'editableOptions'=>[
'valueIfNull' => 'not set',
'inputType' => \kartik\editable\Editable::INPUT_HTML5,
'options' => [
'type' => 'number',
'min' => '0.5',
'step' => '0.5',
],
],
You should use options array as shown above

Related

Wrong rendering search field kartik select2

I use the select2 widget from kartik:
echo $form->field($model, 'person_ids')->widget(Select2::classname(), [
'data' => [1 => 'test1', 2 => 'test2'],
'theme' => Select2::THEME_KRAJEE_BS5,
'hideSearch' => true,
'options' => [
'multiple' => true
],
'pluginOptions' => [
'allowClear' => true
],
])->label('Personal');
The rendering of the search field is wrong - it intends the selected options. Any ideas how to fix this?

How to use selected value in Html::dropDownList with optgroups in Yii2?

in Yii2 I’m trying to choose a specific option with an Html::dropDownList that uses optgroup. I’m able to create the dropdown html just fine using a nested array but how do I select one of the choices? What do I use as the $selection value?
Here is the line of code that I'm currently using. If leave the selection blank, it all works fine, but as soon as I try to select a specific value, I can't get it to work.
echo Html::dropDownList(
'criteria',
['Page 1']['107141'],
[
'Page 1' => [
'107145' => 'Q1: some text',
'107141' => 'Q9: some text',
'107142' => 'Q10: some text',
'107143' => 'Q11: some text',
'107164' => 'Q14: some text',
],
'Page 2' => [
'107195' => 'some text',
],
],
[
'prompt' => [
'text' => 'Choose criteria',
'options' => []
],
'id' => 'criteriaSelector',
'class' => 'criteriaSelector',
'required' => 'required',
]
);
Here is the Yii documentation for the dropdownlist but I can't figure out what to do next:
https://www.yiiframework.com/doc/api/2.0/yii-helpers-basehtml#dropDownList()-detail
Thank you!
For some reason I kept thinking that the the selection needed to be an array element but, of course, since the dropdown option name has to be unique, the selection only needs to be a string. Here is the solution:
echo Html::dropDownList(
'criteria',
'107141',
[
'Page 1' => [
'107145' => 'Q1: some text',
'107141' => 'Q9: some text',
'107142' => 'Q10: some text',
'107143' => 'Q11: some text',
'107164' => 'Q14: some text',
],
'Page 2' => [
'107195' => 'some text',
],
],
[
'prompt' => [
'text' => 'Choose criteria',
'options' => []
],
'id' => 'criteriaSelector',
'class' => 'criteriaSelector',
'required' => 'required',
]
);

Kartik Gridview Switch inputType

I've been looking into this all day, and I'm just wondering if there is built in functionality for Kartik EditableColumn in regards to inputType.
While one can easily apply the SwitchInput to filterType - I can't seem to find a way to handle it in column. It is simply a boolean that I would like handled by this toggle.
While this code produces what I am looking for (aesthetically), I can't produce the expected functionality without strapping it to some JS.
[
//'class' => 'kartik\grid\EditableColumn',
'label' => 'Public',
'hAlign' => 'center',
'vAlign' => 'middle',
'mergeHeader' => true,
'format' => 'raw',
'value' => function ($model) {
return SwitchInput::widget([
'name' => 'test',
'value' => $model->public,
'pluginOptions' => [
'size' => 'mini',
'onText' => 'ON',
'offText' => 'OFF',
],
'labelOptions' => ['style' => 'font-size: 12px;'],
]);
}
],
Produces:

Adding class to cakephp checkbox input instead of div

I'm trying to put the
class="answer_class"
inside all of my checkboxes, however it is creating a div instead and placing the checkboxes there. What should I alter in my code to do what I intend?
$question['question_id'] => array(
'type'=>'select',
'multiple'=>'checkbox',
'options'=> $answers,
'class'=> 'answer_class',
'label' => false
)
You can pass attributes to the options for your checkboxes:-
$question['question_id'] => [
'type' => 'select',
'multiple' => 'checkbox',
'options'=> [
'value' => 1, 'text' => 'Foo', 'class' => 'class1',
'value' => 2, 'text' => 'Bar', 'class' => 'class2'
],
'label' => false
];

Yii2, set default value for select2 widget

use kartik\widgets\Select2;
echo Select2::widget([
'model' => $myModel,
'name' => 'company[]',
'options' => [
'placeholder' => 'Select a company ...',
'multiple' => true,
],
'value' => 6, //doesn't work
'initValueText' => '6', //doesn't work
'pluginOptions' => [
'allowClear' => true,
'ajax' => [
'url' => Url::to(['/company/default/get-company-list']),
'dataType' => 'json',
'data' => new JsExpression('function(term,page) {
return {term : term.term};
}'),
'results' => new JsExpression('function(data,page) {return {results:data.results}; }'),
],
'initSelection' => new JsExpression('function(element, callback) {
$(element).val(6); //doen't work
callback({"text" : "Vendor B", "id" : 6}); // it does only set text, not id
}'),
],
]);
... many many select2 form below too, that named 'company[]'
After form submit, if user come back to this page, I want to set what user selected as default.
How can I set default value for Select2 widget?
When you update the model, it will automatically have the last selected value.
$myModel = new \app\models\myModel;
$myModel->attributes = \Yii::$app->request->post('myModel');