getting an error cant upload the extension kartik select2....
need some ideaaa
using yii want to install the select 2 extension in the branch table...
<div class="branches-form">
<?php $form = ActiveForm::begin(); ?>
<?=$form->field($model,'companies_company_id')->widget(Select2::classname(), [
'data' =>ArrayHelper::map(Companies::find()->all(),'company_id','company_name'),['prompt'=>'Select Company'] ,
'language' => 'en',
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions'=> [
'allowClear' => true
],
]); ?>
<?= $form->field($model, 'branch_name')->textInput(['maxlength' => 100]) ?>
<?= $form->field($model, 'branch_address')->textInput(['maxlength' => 255]) ?>
<?= $form->field($model, 'branch_status')->dropDownList([ 'active' => 'Active', 'inactive' => 'Inactive', '' => '', ], ['prompt' => 'Status']) ?>
<div class="form-group">
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
Properly read this documentation http://demos.krajee.com/widget-details/select2
Try this solution:
Also include use kartik\select2\Select2; at the top of your file.
<?= Select2::widget([
'attribute' => 'companies_company_id',
'model' => $model,
'data' =>ArrayHelper::map(Companies::find()->all(),'company_id','company_name'),['prompt'=>'Select Company'] ,
'language' => 'en',
'options' => ['placeholder' => 'Select a state ...'],
'pluginOptions'=> [
'allowClear' => true
],
]) ?>
Related
I am working a yii2 page and it's giving me problems adding a placeholder or a prompt to Select2 Widget. Here is my code:
<?php
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use kartik\datecontrol\DateControl;
use yii\helpers\ArrayHelper;
/**
* #var yii\web\View $this
* #var app\models\FinancialAccounts $model
* #var yii\widgets\ActiveForm $form
*/
?>
<div class="financial-accounts-form">
<?php $form = ActiveForm::begin(['type' => ActiveForm::TYPE_VERTICAL]); echo Form::widget([
'model' => $model,
'form' => $form,
'columns' => 1,
'attributes' => [
'type_id' => ['type' => Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\Select2', 'options' => ['data'=>ArrayHelper::map(app\models\FinancialAccountType::find()->all(), 'type_id', 'name')]],
'account_name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Account Name...', 'maxlength' => 100]],
'account_code' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Account Code...', 'maxlength' => 10]],
'parent_id' => ['type' => Form::INPUT_WIDGET, 'widgetClass'=>'\kartik\widgets\Select2', 'options' => ['data'=>ArrayHelper::map(app\models\FinancialAccounts::find()->all(), 'account_id', 'account_name'), 'placeholder' => 'Select a Parent Account...']],
'description' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => 'Enter Description...', 'maxlength' => 250]],
],
]);
echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'),
['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']
);
ActiveForm::end(); ?>
</div>
The problem is in the parent_id attribute as I cannot add a placeholder as an option as most of the tutorials recommend. Everytime I try that, I get an error as this:
Unknown Property – yii\base\UnknownPropertyException
Setting unknown property: kartik\widgets\Select2::placeholder
Does anyone know how I can solve this? My main problem is that I cannot leave this option as blank when submitting data yet that is one of the possibility. It forces me to submit an item selected.
You'll note that if you follow the examples in the documentation carefully, placeholder needs to be wrapped within an options array.
'parent_id' => [
'type' => Form::INPUT_WIDGET,
'widgetClass' => '\kartik\widgets\Select2',
'options' => [
'data' => ArrayHelper::map(app\models\FinancialAccounts::find()
->all(), 'account_id', 'account_name'),
'options' => ['placeholder' => '...'],
'pluginOptions' => ['allowClear' => true],
]
],
i got problem when i tried to post submitbutton value.
<?= Html::submitButton('Save', ['value' => 'save','class' => 'btn green','name' => 'submit']) ?>
When i tried with that code, my value posted but i should click the button twice.
<?= Html::submitButton('Save', ['value' => 'save','class' => 'btn green','name' => 'button1']) ?>
But when i changed name button, the value not post.
Any idea to solve this problem?
This my form :
<?php $form = ActiveForm::begin(); ?>
<?= Html::activeDropDownList($storev, 'id_store_v',$itemsv,
[
'prompt'=>'--Select Dealer--',
'class'=>'form-control input-sm select2-multiple',
//'onchange'=>'$("#namev").val($("#id_store_v option:selected").text());',
'onchange'=>'$("input#idv").val($(this).val()),
$.post("index.php?r=sync/listsv&id='.'"+$(this).val(), function( data ) {
$("select#storev-address").html(data);
});'
])
?>
<?= $form->field($storev, 'id_store_v')->hiddenInput(['maxlength' => true, 'id'=>'idv'])->label(false) ?>
<?= $form->field($storev, 'address')->dropDownList(
ArrayHelper::map(Storev::find()->all(),'id_store_v','address'),
[
'prompt'=>'',
'class'=>'form-control input-sm select2-multiple',
'disabled'=> true,
])
?>
<?= Html::activeDropDownList($storetd, 'id',$itemstd,
[
'prompt'=>'--Select Dealer--',
'class'=>'form-control input-lg select2-multiple',
'multiple'=>'multiple',
//'onchange'=>'$("#namev").val($("#id_store_v option:selected").text());',
'onchange'=>'$("input#idtd").val($(this).val())'
])
?>
<?= $form->field($storetd, 'id')->hiddenInput(['maxlength' => true, 'id'=>'idtd'])->label(false) ?>
<?= Html::submitButton('Save', ['value' => 'save','class' => 'btn green','name' => 'button1']) ?>
<?= Html::submitButton('Check', ['value' => 'check','class' => 'btn yellow','name' => 'button1']) ?>
try using a simple
<?= Html::submitButton('Save', ['class' => 'btn btn-green']) ?>
and if you need a value try
<?= Html::submitButton('Save', ['class' => 'btn btn-green', 'value'=>'save' ]) ?>
Try this one
View:
<?= Html::submitButton('Save', ['name' => 'form', 'value' => 'one']) ?>
Controller
if(Yii::$app->request->post('form') == 'one'){
}
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(); ?>
how to disabled textInput in ActiveForm ?
i try like this but can't
<?= $form->field($model, 'title_series')->textInput(['class' => 'form-control class-content-title_series', 'placeholder' => 'Title', 'disabled' => 'disabled'])->label(false) ?>
'disabled' => 'disabled or 'disabled' => true
both of them can't too
I don't really know yii2/ActiveForm, but I believe you need to do it this way:
<?= $form->field($model, 'title_series')->textInput(['class' => 'form-control class-content-title_series', 'placeholder' => 'Title', 'disabled' => true])->label(false) ?>
To ensure that the field values are send on submit, use
echo $form->field($model, 'name')->textInput([
'readonly' => true,
]);
This solution won in 50 different tries.
I think issue was with your label thing
<?= $form->field($model, 'title_series')->textInput(['class' => 'form-control class-content-title_series', 'placeholder' => 'Title', 'disabled' => 'true'])->label(''); ?>
This is working, keep the disabled in same array than 'value'
<?= $form->field($model, 'type')->textInput(['value' => $type,'disabled' => true]) ?>
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]),
...