Here I'm stuck with one point when I open any form than i want to enable to choose one dropdown but if I want to update that from this dropdown field will be disabled.
So Which syntax I put in the form?
$form->field($model, 'branch_id', [])->dropdownList(BranchMaster::getBranchList(Common::getCurrentCompany()),
[
'class' => 'chosen-select-width branch_id',
'prompt' => Common::translateText('BRANCH_TEXT')
]
);
here is my form field ,now i want it to disable when this form is open for update action.
Try this:
<?= $form->field($model, 'branch_id', [])->dropdownList(BranchMaster::getBranchList(Common::getCurrentCompany()), [
'class' => 'chosen-select-width branch_id',
'prompt' => Common::translateText('BRANCH_TEXT'),
'disabled' => !$model->isNewRecord,
]) ?>
Related
So I am doing a form using the kartik form builder and I am using the input_widget kartik\date\datepicker. When I use the datepicker only it submits but when I go to the item view the date is set like 30/11/-0001. The solution I found when I first had this problem was using not only the date picker but also the date control (also from kartik). But at that time I was using the default yii form and it was possible to use multiple widgets in a single attribute. Now im using the kartik form builder and i cant set more than one widget and its class. How can I do to use both date picker and date control in a single attribute at kartik's form build or, if anyone knows, how to solve this problem without having to add the date control?
before it was like:
<?= $form->field($model, 'validadeCertificado')
->textInput()
->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
]
])
->widget(DateControl::className(), [
'type'=>DateControl::FORMAT_DATE,
'ajaxConversion'=>false,
'widgetOptions' => [
'pluginOptions' => [
'autoclose' => true,
'language' => 'pt-BR',
]
]
]);
?>
now it is like:
echo Form::widget([ // 3 column layout
'model'=>$model,
'form'=>$form,
'columns'=>12,
'compactGrid'=>true,
'attributes'=>[
'validadeCertificado'=>[
'type'=>Form::INPUT_WIDGET,
'widgetClass'=>'\kartik\date\DatePicker',
'options' => [
'pluginOptions' => [
'format' => 'dd-mm-yyyy',
'autoclose'=>true,
'todayHighlight' => true
],
],
'columnOptions'=>['colspan'=>3],
],
<!--(other attributes)-->
]
]);```
I just wanted the date to be correctly inserted in the mysql database but it is inserted into the database as 0000-00-00
Heeeelp
I am trying this code but does not work.
$form=ActiveForm::begin(['id'=>
'id' => 'login-form',
'options' => ['class'=>'darkBg','enableClientValidation'=>false,'validateOnBlur' => false],
]); ?>
<?= $form->field($model, 'email')->textInput(['class'=>'form-control','type'=>'text','enableClientValidation'=>false,])->label(false) ?>
I wanted to disable Yii2 default error msg.
You just have to add
->error(false)
This way no text is being shown, but field still gets marked red on failure.
i have the below form field of dropdown list.My problem is default option selected is not happening.The option value is coming as POST request.
$_REQUEST['id']=8;
<?= $form->field($model, 'id')->dropDownList(ArrayHelper::map($model,'id','name'),
[
isset($_REQUEST['id'])?'"options"=>[$_REQUEST["id"]=>["selected"=>true]]':'',
'prompt' => 'Select ',
'onChange' => '$.get("'.Yii::$app->urlManager->createUrl('data/datalist?id=').'"+$(this).val(),function(data){$("#dashboard-id").html(data);})',
])
?>
you have done the mistake in options.Try like below:
<?= $form->field($model, 'id')->dropDownList(ArrayHelper::map($model,'id','name'),
[
'options'=>isset($_REQUEST['id'])?[$_REQUEST["id"]=>["selected"=>true]]:'',
'prompt' => 'Select ',
'onChange' => '$.get("'.Yii::$app->urlManager->createUrl('data/datalist?id=').'"+$(this).val(),function(data){$("#dashboard-id").html(data);})',
])
?>
I want to put a checkbox on each row in a GridView, and also link that GridView with a submit button, like this image:
The objective is for each checked and unchecked row do an Insert on a certain table from the database. I need help, please.
This the code for the GridView I have for now:
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
'rutAlumno',
'nombreAlumno',
'apellidoAlumno',
'cursoAlumno',
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
To add a CheckboxColumn to the yii\grid\GridView, add it to the columns configuration as follows
['class' => CheckboxColumn::className()],
Users may click on the checkboxes to select rows of the grid. The selected rows may be obtained by calling the following JavaScript code:
var keys = $('#grid').yiiGridView('getSelectedRows');
// keys is an array consisting of the keys associated with the selected rows
For more Here
<?= GridView::widget([
'dataProvider' => $dataProvider,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
['class' => 'yii\grid\CheckboxColumn'],
'rutAlumno',
'nombreAlumno',
'apellidoAlumno',
'cursoAlumno',
//['class' => 'yii\grid\ActionColumn'],
],
]); ?>
It will generate checkboxes for each row. Now right the js script
$('.btn').on('click',function(e){
var selectedKeys = $('#your-grid-id').yiiGridView('getSelectedRows');
/* your code */ });
Hi i am using kartik select2 in my yii application. The select box for selecting multiple options is working fine. However i am facing one small issue.
Like if i type ba then it will display all matching options. but when i press enter then Bakam get selected but the text ba remains in select box. It should get removed.
Here is code for my select box
<?= $form->field($model, 'area')->widget(Select2::classname(), [
'data' => [],
'options' => ['placeholder' => 'Select Location'],
'pluginOptions' => [
'closeOnSelect' => false,
'tags' => false,
'multiple' => true,
],
])->label("Reassign Location")
?>
I checked it on kartik website the code seems fine then why the text remains there?
Set 'closeOnSelect' => true, in pluginOptions to remove selected option.