How do you set a textInput to readOnly? I have the sample code below:
<?= $form->field($model, 'GrossPay')->textInput(['id'=>'GrossPay','readonly'=> true])?>
It's readOnly not readonly but it does not make a difference here.
<?= $form->field($model, 'GrossPay')->textInput(['id'=>'GrossPay','readonly'=> true])?>
Related
I'm using Yii2, activeForm and the Yii2 pjax widget to handle an search form with result list.
But for layout reason, I have to split this package to two parts: the search form, which should be located in the header of the page and the result listing, which should be placed in the middle of the page.
This means it's not possible to do something like that (pseudocode):
Pjax::begin
$form=>activeForm::begin..
ActiveForm::end();
ListView::widget...
Pjax::end()
What I need is placing the activeForm in the layout header, placing the ListView wiget in the center of the page and telling pjax: read the input from the form, load data from Server and replace the clist view.
Is that possible using the build-in functionality of the widgets?
I didn't get it working, maybe I misunderstood the basic concept?
Using gridview (or widget which use searchModel) you could use a separated model for modelSearch in header and show the resul in the gridview palced where you prefer
in this way you need only a pjax block
<?= $this->render('_search', ['model' => $searchModel]); ?>
<?php Pjax::begin(); ?>
<?= GridView::widget([
...
]); ?>
<?php Pjax::end(); ?>
for other soluzione not based on gridview and when you need multiple seprataed pjax block
You could try using named pjax block using a value for id
<?php \yii\widgets\Pjax::begin(['id'=>'pjax-block1']); ?>
....
....
<?php \yii\widgets\Pjax::end(); ?>
<?php \yii\widgets\Pjax::begin(['id'=>'pjax-block2']); ?>
....
....
<?php \yii\widgets\Pjax::end(); ?>
and if you need you could manage specific refresh using jquery
$.pjax.reload({container: '#pjax-block1', async: false});
$.pjax.reload({container: '#pjax-block2', async: false});
My controller
public function actionIndex()
{
return $this->render('index');
}
In the view I call a series of widgets. All the logic inside the widgets, they do not have any input parameters. In each block for every widget I want to add a button to update the widget inside this block.
<?= Html::a("Обновить", ['???'], ['class' => 'btn btn-sm btn-default', 'data-pjax' => '#formsection']) ?>
I put widget in pjax
<?php Pjax::begin(['id' => 'formsection', 'linkSelector' => '#chart a']); ?>
<div class="chart" id="chart" style="height: 200px; position: relative;">
<?= Chart::widget(); ?>
</div>
<?php Pjax::end(); ?>
How to assign a specific block to a button?
As i understand the chart is drawn via some values from the database which are frequently updated and you want those changes to be reflected in the chart when you click the reload button.
If the above is correct then you should use $.pjax.reload simply to reload the section bind the click event to the button
$this->registerJs('
jQuery(document).on("click", "#my-button", function(event){
$.pjax.reload({container:"#formsection",timeout:1000})
}
);
');
Hope that helps.
I'm trying to add a modal to my navbar.
This is my \views\project_form.php:
<?php Modal::begin(['id' => 'modal', ?>
<?= $form->field($model, 'Wert')->textInput(['maxlength' => true]) ?>
<?php Modal::end(); ?>
and this is my Controller:
function actionShowmodal(){
$js='$("#modal").modal("show")';
$this->getView()->registerJs($js);
return $this->render('create');
}
I did this as it was described here how can I add modal to navbar in yii2 using yii2 -bootstrap extension?.
When I use a modal navbar in my index.php it works. But when I use a modal navbar in my form, an error is issued: Undefined variable: model.
How can I fix it?
In order to create a form in modal you need to pass the respective model for the form
function actionShowmodal(){
$model = new RespectiveModel(); //Model For the Form
$js='$("#modal").modal("show")';
$this->getView()->registerJs($js);
return $this->render('create',["model"=>$model]);
}
and in your "create.php" view file where you are rendering the form, pass the model variable again
echo $this->render('project_form',["model"=>$model]);
I am using the the Cake
<?= $this->Form->input('vehicles._ids', ['label' => 'Vehicle', 'options' => $vehicles, 'multiple' => 'checkbox', 'ng-model' => 'vehicles']); ?>
For each check box I want to add the custom attributes: 'ng-model'
I can see that the generation of multiple checkboxes is handled by the class file MultiCheckboxwidget.php and checkboxes use the 'checkbox' template:
'checkbox' => '<input type="checkbox" name="{{name}}" value="{{value}}"{{attrs}}>',
But since by default this uses {{attrs}} I can't see why my custom ng-model attribute isn't being added to the generatred form input. Instead this is the amrk-up crearted by the helper:
<input type="checkbox" name="vehicles[_ids][]" value="1"id="vehicles-ids-1" class="ng-valid">
How can I add ng-model to each of the checkbox inputs?
Upgrading my verison of CakePHP form 3.3.12 to 3.4 resolved the issue, the formhelper must have been refined in the latter versions.
I have a dropdown list in my form, and I would like to enable the user to an option of 'other', which would enable him to insert a value in to a text box, instead of a value from the dropdownlist.
Is that possible?
<?= $form->field($model, 'institution')->dropDownList(ArrayHelper::map(Institution::find()->all(), 'iId', 'name'), ['class'=>'form-control inline-block']); ?>
The same thing I would like to do with a radioList.
<?= $form->field($model, 'selfDescription')->radioList(array('good'=>'good','very good'=>'very good','best'=>'best')); ?>
thanks.
First. Add "other" option to dropDownList. And handle it in your frontend with JS
$form
->field($model, 'institution')
->dropDownList(
ArrayHelper::map(Institution::find()->all(),
'iId',
'name'
) + ['other' => 'Other'],
[
'class'=>'form-control inline-block',
// next code disables text field when any but "other" option is selected
// works for jQuery 1.6+
'onchange' => new JsExpression('
$("#textFieldSelector").prop("disabled", $(this).find("option:selected").val() != "other");'),
]
);
Then you need to set properly your validators. Just add
['textField', 'required', 'when' => function($model) {
return $model->institution === 'other';
}]