How can I trigger click on 2nd tab event via butto, with jquery?
$('#packingGrid2').trigger('click');
I tried do this with trigger pasted above, but it doesnt work. Any thoughts?
#Keydose, there is my code.
$items = [
[
'url' => \Yii::$app->params['pjax_enabled']?null:Url::to(['step_1', 'tab' => 'packingGrid1']),
'label' => '<i class="glyphicon glyphicon-check"></i> Weryfikacja linii',
'content' => \Yii::$app->controller->renderPartial('step_1', [
'gridId' => 'packingGrid1',
'model' => $model,
'form' => $form,
]),
'linkOptions' => [
'data-id' => 'packingGrid1',
],
],
[
'url' => \Yii::$app->params['pjax_enabled']?null:Url::to(['step_2', 'tab' => 'packingGrid2']),
'label' => '<i class="glyphicon glyphicon-user"></i> Ustawienia pracowników',
'content' => ($model->isNewRecord) ? '<strong>Uzupełnij weryfikację linii</strong>' :
\Yii::$app->controller->renderPartial('step_2', [
'gridId' => 'packingGrid2',
'model' => $model,
'form' => $form,
]),
'linkOptions' => [
'data-id' => 'packingGrid2',
],
'active' => ($model->isNewRecord) ? false : true,
],
],
];
echo TabsX::widget([
'items' => $items,
'position' => TabsX::POS_ABOVE,
'encodeLabels'=>false,
'bordered'=>true,
]);
Related
I have a GridView of a index view with some columns. I added a print button that link to a URL that has to be opened in a new window.
This code work but the URL is not open in a new window.
'columns' => [
'column1',
'column2',
'column3',
'column4',
'column5',
[
'class' => 'yii\grid\ActionColumn',
'template' => '{download} {update} {delete}',
'buttons' => [
'download' => function ($url, $model) {
return Html::a(
'<span class="fa fa-print"></span>',
'/disposicion-licencia/print-estival?id=' . $model->id,
[
'title' => 'Download',
'data-pjax' => '0',
]
);
},
],
],
]
I think I need JavaScript code like this:
window.open('/disposicion-licencia/print-estival?id=$id');
But I don't know where to use it.
For a new window you need 'target' => '_blank':
return Html::a(
'<span class="fa fa-print" ></span>',
'/disposicion-licencia/print-estival?id=' . $model->id,
[
'title' => 'Download',
'data-pjax' => '0',
'target' => '_blank',
]
);
I use the yii2 kartik switch input with the type radio and i want to get the value of the selected option in javascript (specially in a JsExpression), here is my code :
$model->orientation = 'Portrait';
echo $form->field($model, 'orientation')->widget(SwitchInput::classname(), [
'name' => 'information_orientation',
'type' => SwitchInput::RADIO,
'value' => 'Portrait',
'items' => [
['label' => 'Portrait   ', 'value' => 'Portrait'],
['label' => 'Paysage   ', 'value' => 'Paysage'],
],
'pluginOptions' => [
'onText' => 'Oui',
'offText' => 'Non',
'onColor' => 'success',
'offColor' => 'danger',
'size' => 'mini'
],
'labelOptions' => ['style' => 'font-size: 13px'],
]);
I have tried :
$([name='information-orientation']).val()
But it returned an undifined value
SwitchInput class does not care about the name property you give it
according to their docs, you need to wrap name in a options array
echo $form->field($model, 'orientation')
->widget(SwitchInput::classname(), [
'options' => ['name' => 'information_orientation'],
'type' => SwitchInput::RADIO,
....
from docs:
options: array the HTML attributes for the widget input tag.
edit:
you can then use the following
// to get value:
$("[name='information_orientation']").val()
// to check if the switch is or on off
$("[name='information_orientation']").prop('checked')
I'm using X-cart 5 and trying to create a new form following
this tutorial from X-cart's website. I have successfully created the form and it is displayed correctly. However, if I specify field type that is not X-cart's (for instance if I use Symfony\Component\Form\Extension\Core\Type\PasswordType), the field is emptied on blur.
Sample code generating the form, in which email and passwords have the issue I described, while the sample field is working correctly:
protected function defineFields()
{
$schema = [
self::SECTION_DEFAULT => [
'email' => [
'label' => static::t('E-mail'),
'required' => true,
'type' => 'Symfony\Component\Form\Extension\Core\Type\EmailType',
'position' => 100
],
'password' => [
'label' => static::t('Password'),
'type' => 'Symfony\Component\Form\Extension\Core\Type\PasswordType',
'required' => true,
'position' => 100,
],
'password_conf' => [
'label' => static::t('Confirm password'),
'type' => 'Symfony\Component\Form\Extension\Core\Type\PasswordType',
'required' => true,
'position' => 100
],
'sampleField' => [
'label' => static::t('Sample field'),
'type' => 'XLite\View\FormModel\Type\TextareaAdvancedType',
'position' => 100
]
]
];
return $schema;
}
Do you have any ideas why this happens?
Thanks!
I have six fields which are editable in my Yii2 form widget. What i want to do is once i input integer values into editable fields calculate "Green leaf net weight" automatically based on the given input. my coding are work perfectly. But the problem is if i change already input value in the fields it'll not update the the "Green leaf net weight" read only field.
$(document).ready(function(){
var A = $('#A');
var B = $('#B');
var C = $('#C');
var D = $('#D');
var E = $('#E');
E.change(function(e){
var result = ((A.val() - B.val()) * C.val())/100;
var result2 = ((A.val() - B.val()) * D.val()) / 100;
var final = ((A.val() - B.val()) - result - result2) - E.val();
Math.round(final);
$('#F').val(final);
})
});
my form widget coding (updated code)
<?php $form = ActiveForm::begin(); ?>
<?= $form->field($model, 'Gross_weight',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'A', **'class' => 'factors'** ]) ?>
<div class="panel panel-primary" style="padding: 10px;">
<div style="text-align: center; color: #008000;"><b>Deductions</b></div>
<?= $form->field($model, 'Bags_count',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput() ?>
<?= $form->field($model, 'Bags_weight',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'B', **'class' => 'factors'** ]) ?>
<?= $form->field($model, 'Course_leaf',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'C', **'class' => 'factors'**]) ?>
<?= $form->field($model, 'Water',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'D', **'class' => 'factors'**]) ?>
<?= $form->field($model, 'Boiled_leaf',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['id' => 'E',**'class' => 'factors'**]) ?>
</div>
<?= $form->field($model, 'Greanleaf_net_weight',[
'feedbackIcon' => [
'default' => 'shopping-cart',
'success' => 'ok',
'error' => 'exclamation-sign',
]
])->textInput(['disabled' => 'disabled', 'id' => 'F']) ?>
Thanks for everyone.
Inorder to execute the calculation on the change of all the input fields you have to add a class to all the input fields and use that class as the jQuery selector for change event.
<input id="A" class="factors" ... />
...
...
$(".factors").change(function(e) {
...
...
}
See Demo
How to draw a CGridView after document ready? I have Yii framework 1.14, jquery and jquery.ui successfully loaded!
Console.error! Because the grid is draw after document ready
TypeError: jQuery(...).dialog is not a function
jQuery("#dialog").dialog();
My code:
[
'class' => 'zii.widgets.grid.CButtonColumn',
'template' => '{edit}',
'headerHtmlOptions' => ['class' => 'col-lg-1', 'style' => 'text-align:center'],
'buttons' => [
'edit' => [
'label' => '<span class="glyphicon glyphicon-comment"></span>',
'url' => "Yii::app()->controller->createUrl('ViewComments',['key'=>\$data->key])",
'imageUrl' => null,
'options' => [
'style' => 'color: black',
'rel' => 'tooltip',
'data-toggle' => 'modal',
'data-target' => "#myModal",
'title' => 'Комментировать',
'ajax' => [
'type' => 'post',
'url' => 'js:$(this).attr("href")',
'dataType' => 'html',
'success' => 'js:function(data){
jQuery("#dialog").dialog();
}'
],
],
],
]
],
Have you tried reloading js in your view
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript('jquery.ui');