I want to update query when user field search field and click on button "search", but this is not send my get parameters to update action ..
here is view:
<?php
Pjax::begin([
'enablePushState' => true, // I would like the browser to change link
'timeout' => 100000 // Timeout needed
]);
echo LinkPager::widget([
'pagination' => $pagination,
'hideOnSinglePage' => true,
'prevPageLabel' => 'Предишна',
'nextPageLabel' => 'Следваща',
'firstPageLabel' => 'Начало',
'lastPageLabel' => 'Край'
]); ?>
<?php $form = ActiveForm::begin([
'action' => ['update'],
'method' => 'get',
]); ?>
<input type="text" id="fname" class="form-control search-option-input" placeholder="търси прецификация по име, номер" name="search-query-main" value=' '>
<div class="form-group">
<?= Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
<?= Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>
i use pjax for pager with result of all specification, because they are over 600 ... this code is in view _form and i want to send it with this search word to controller action Update, who can not work without $_GET['id']
If you want to pass ID in URL you can add it into action URL of your form:
<?php $form = ActiveForm::begin([
'action' => ['update', 'id' => $id],
'method' => 'get',
]); ?>
Related
I have 2 modals in one active form. Let's say first one is modal-ticket and second one is contract-ticket. First time, I click button to show modal-ticket, and it was fine, but when I click button to show modal-contract, it also call script modal-ticket or otherwise. why?
this is my code.
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalTicketList',
'data-toggle'=>"modal",
'data-target'=>"#modalTicketList",
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary',
'id' => 'BtnModalContractList',
'data-toggle'=>"modal",
'data-target'=>"#modalContractList",
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'header' => 'Ticket List',
'id' => 'modalTicketList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentTicket'></div>";
Modal::end();
?>
<?php
Modal::begin([
'header' => 'Contract List',
'id' => 'modalContractList',
'size' => 'modal-lg',
'class' => 'style=width:auto'
]);
echo "<div id='modalContentContract'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$('#BtnModalTicketList').click(function(e){
e.preventDefault();
$('#modalTicketList').modal('show')
.find('#modalContentTicket')
.load($(this).attr('value'));
return false;
});
$('#BtnModalContractList').click(function(e){
e.preventDefault();
$('#modalContractList').modal('show')
.find('#modalContentContract')
.load($(this).attr('value'));
return false;
});
JS;
$this->registerJs($script);
?>
this are the error found in console web browser
GET http://localhost/pks/web/ticket-timbangan/get-ticket?id=1 404 (Not Found)
GET http://localhost/pks/web/contract/get-contract?id=2 404 (Not Found)
please help.
Try This: using one modal on your form:
<?php $form = ActiveForm::begin(); ?>
<div id="BtnSearchTicket">
<?= Html::button('Search Ticket', [
'value' => Url::to('../ticket-timbangan/list'),
'class' => 'btn btn-primary showModal',
'id' => 'BtnModalTicketList',
'title' => 'Search Ticket',
]) ?>
</div>
<div id="BtnSearchContract">
<?= Html::button('Search Contract', [
'value' => Url::to('../contract/list'),
'class' => 'btn btn-primary showModal',
'title' => 'Search Contract',
'id' => 'BtnModalContractList',
]) ?>
</div>
<?php ActiveForm::end(); ?>
<?php
Modal::begin([
'headerOptions' => ['id' => 'modalHeader'],
'id' => 'modal',
'size' => 'modal-lg',
'closeButton' => [
'id'=>'close-button',
'class'=>'close',
'data-dismiss' =>'modal',
],
'class' => 'style=width:auto',
'clientOptions' => [
'backdrop' => false, 'keyboard' => true
]
]);
echo "<div id='modalContent'></div>";
Modal::end();
?>
<?php
$script = <<< JS
$(document).on('click', '.showModal', function(){
if ($('#modal').hasClass('in')) {
$('#modal').find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
} else {
$('#modal').modal('show')
.find('#modalContent')
.load($(this).attr('value'));
document.getElementById('modalHeader').innerHTML = '<h4>' + $(this).attr('title') + '</h4>';
}
});
JS;
$this->registerJs($script);
?>
From viewing your code what calls my attention is how you use the Url::to() function. Not sure why you use ../. I have fiddled with using more than one modal in a form and the code is similar to what your are doing. I suggest you try changing your Url::to() function as follows:
Url::to('/ticket-timbangan/list')
and
Url::to('/contract/list')
Another suggestion would be to try with
Yii::$app->urlManager->createUrl('/ticket-timbangan/list')
and
Yii::$app->urlManager->createUrl('/contract/list')
Let me know if this helps.
First, many thanks to kalu who has helped me 2 days to solve my problem. Two modals which contains grid need to define different classes to prevent execute previous script.
'value' => Url::to('../ticket-timbangan/list') and 'value' => Url::to('../contract/list'), both has two gridview and same select-row class. This class is root cause of the problem, because it's same class and execute both script.
Thanks Kalu, you save my day.
In controller file i print this,
in controller am getting NULL after printing.
how to the know if button is clicked ?
var_dump(\Yii::$app->request->post('submit'));
In view file
<?php $form = ActiveForm::begin([
'id' => 'button',
]); ?>
<?= Html::submitButton('submit', ['name' => 'submit', 'value' => 'submit_1', 'class' => 'btn']) ?>
<?php ActiveForm::end(); ?>
What I want to do is to change from bootstrap vertical to horizontal form and this is what I've tried:
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'action' => ['index'],
'method' => 'get',
'fieldConfig' => [
'horizontalCssClasses' => [
'label' => 'col-sm-2',
'offset' => 'col-sm-offset-2',
'wrapper' => 'col-sm-4',
],
],
]); ?>
<div class="row">
<div class="col-md-6">
<?= $form->field($model, 'firstname') ?>
<?= $form->field($model, 'lastname') ?>
</div>
<div class="col-md-6">
<?= $form->field($model, 'email') ?>
<?= $form->field($model, 'bla') ?>
</div>
</div>
<?php ActiveForm::end() ?>
but it gave me an error Setting unknown property: yii\widgets\ActiveForm::layout
Please help!!!
For layout option to work ActiveForm must be instance of yii\bootstrap\ActiveForm instead of yii\widgets\ActiveForm.
Change your use statement.
In boostrap you can use
<form class="form-inline"> // for inline fields form
or
<form class="form-horizontal"> // for horizonatal fields form
eg:
<?php $form = ActiveForm::begin([
'layout' => 'horizontal',
'action' => ['index'],
'method' => 'get',
'class' => 'form-horizontal',
]); ?>
I have a form field "dob[]" with array input like
<?php $form = ActiveForm::begin();
for($i=0;$i<= 3;$i++):
echo $form->field($model, 'dob[]')->widget(DatePicker::classname(), [
'options' => ['placeholder' => 'Date Of Birth'],
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'format' => 'mm/dd/yyyy',
'autoclose' => true,
]
]);
endfor; ?>
<div class="form-group">
<?= Html::button('Submit', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
Datepicker working only on first "dob" field but rest of the field having only button format of datepicker but calendar not working.
This is because the javascript cannot determine the correct input fields, after the first one. Take a look in your source code. All widgets have properly the same id and/or name. You have to setup a unique ID for each of the generated widgets.
By the way, it is always a good approach to name form data accordingly.
That is documented at the demo page.
The following should work:
<?php
$form = ActiveForm::begin();
for ($i=0; $i < 3; $i++) {
echo $form->field($model, 'date_end')->widget(DatePicker::classname(), [
'options' => [
'placeholder' => 'Date Of Birth',
'name' => 'DOB' .$i,
'id' => 'DOB-ID' . $i,
],
'type' => DatePicker::TYPE_INPUT,
'pluginOptions' => [
'format' => 'mm/dd/yyyy',
'autoclose' => true,
],
]);
}
?>
<div class="form-group">
<?= Html::button('Submit', ['class' => 'btn btn-success']) ?>
</div>
<?php ActiveForm::end(); ?>
My application have to have multiple language, so I decided to separate each language by using tab (Yii2 gui), but how can I render the form in side the 'content' key?
<?php
$language_tab=[];
$increment=0;
$content="I love you";
foreach($language as $obj){
$language_tab[$increment] = array('label' => $obj->name ,'content' => $content);
$increment++;
}
echo Tabs::widget([
'items' => $language_tab,
'options' => ['tag' => 'div'],
'itemOptions' => ['tag' => 'div'],
'headerOptions' => ['class' => 'my-class'],
'clientOptions' => ['collapsible' => false],
]);
?>
<div class="status-form">
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'date_created')->textInput() ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
I just wanna change from $content to the form below.
Please help!!!
You may create separate view for the form and render it:
...
'content' => $this->render('_language_form', ['language' => $obj, 'model' => $model]),
...