I have a page which consist of 5 tab. 1st and 2nd tab is just normal filling form while my 3rd,4th and 5th tab is the index of other index page (which I can create update and delete the data). Below is the code for the form.
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
use kartik\tabs\TabsX;
use kartik\date\DatePicker;
use frontend\models\OpStates;
use frontend\models\OpContact;
use frontend\models\OpCountries;
use frontend\models\OpClient;
use frontend\models\OpUnit;
use frontend\models\OpMaintenanceCharges;
use yii\helpers\ArrayHelper;
use yii\helpers\Url;
$this->title = 'Change Profile';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="site-changedetails">
<?php $form = ActiveForm::begin(['id'=>'changedetails-form',]); ?>
<?= TabsX::widget([
'position' => TabsX::POS_ABOVE,
'align' => TabsX::ALIGN_LEFT,
'items' => [
[
'label'=>'Client Details',
'content'=>
'<div class="row">
<div class="col-md-12">'.
$form->field($model, "client_code")->textInput(["maxlength" => true]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "contact_id")->dropDownList(ArrayHelper::map(OpContact::find()->all(),'id','code')).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "unit_id")->dropDownList(ArrayHelper::map(OpUnit::find()->all(),'id','code')).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'country_id')->dropDownList(ArrayHelper::map(OpCountries::find()->all(),'id','name'),
[
'prompt' => 'Select Country',
'onchange' => '
$.post("index.php?r=op-states/lists&id='.'" + $(this).val(), function(data){
$("select#opclient-states_id").html(data);
});'
]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'states_id')->dropDownList(ArrayHelper::map(OpStates::find()->all(),'id','state_name'),
[
'prompt' => 'Select States',
]).'
</div>
</div>
<div class="row">
<div class="col-md-6">'.
$form->field($model, 'city')->textInput(['maxlength' => true]).'
</div>
<div class="col-md-6">'.
$form->field($model, 'postcode')->textInput().'
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-md-1 col-md-offset-11">'.
Html::submitButton('Save',['class'=>'pull-right btn btn-primary','style'=>'width:70px; height:40px;','name'=>'button1']).'
</div>
</div>
</div>
'
],
[
'label'=>'Client Details 2',
'content'=>
' <div class="row">
<div class="col-md-12">'.
$form->field($model, "charge_interest")->dropDownList(['Yes'=>'Yes','No'=>'No']).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, 'interest_effective_date')->widget(DatePicker::classname(), [
'pluginOptions' => [
'autoclose'=>true,
'format' => 'yyyy-mm-dd',
'todayHighlight' => true,
'todayBtn' => true,
]
]).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "charge_reminder")->dropDownList(['Yes'=>'Yes','No'=>'No']).'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "external_debtor_code")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address1")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address2")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address3")->textInput().'
</div>
</div>
<div class="row">
<div class="col-md-12">'.
$form->field($model, "mailing_address4")->textInput().'
</div>
</div>
'
],
[
'label'=>'Maintenance Charges',
'content' => $this->render('//op-maintenance-charges/index', [
'model'=>$model,
'dataProviderMainCharges' => $dataProviderMainCharges,
]),
],
[
'label'=>'Misc Charges',
'content' => $this->render('//op-misc-charges/index', [
'model'=>$model,
'dataProviderMiscCharges' => $dataProviderMiscCharges,
]),
],
[
'label'=>'Occupier Details',
'content' => $this->render('//op-occupier/index', [
'model'=>$model,
'dataProviderOccupier' => $dataProviderOccupier,
]),
],
]
]); ?>
<?php ActiveForm::end(); ?>
The problem is the 1st index page is working normally. Click to see - Working normally
The 2nd index page n 3rd index cannot work. The form wont even come out. The screen just become darker and I cant click anything like this Click to see - Cant Work
Anyone can help or have any idea on how to fix it? Thanks
Related
I have two activeform in my view and one of them use pjax. And both of them requires second click to submit. I don't know what I am doing wrong. I search this problem in internet, but meet other cases of second click
<?php Pjax::begin(['id' => 'workers', "timeout" => 50000], ["options" => ["timeout" => 5000]]);?>
<?php
echo $this->render('_show', [
"model" => $searchModel,
"filials" => $filials,
"workers" => $workers,
"posts" => $posts,
]);
echo $this->render('_handle_form');
?>
<div class="row js-loader">
<div class="col-lg-12 col-md-12">
<div class="table-responsive">
<?=GridView::widget([
'dataProvider' => $dataProvider,
'emptyText' => 'Нет результатов',
'tableOptions' => ['class' => 'table table-hover table-claim table-claimadm', 'style' => 'font-weight:600;'],
'rowOptions' => ['class'=>'row-without-border row-open'],
'layout' => "{items}{pager}",
'columns' => [
[
...
]
]);?>
</div>
</div>
</div>
<?php Pjax::end();?>
<script>
window.onload = function () {
$(document).on('pjax:send', function (event) {
tbody = $('#' + event.target.id).find(".js-loader");
if (tbody.length != 0) {
tbody_height = tbody.height();
tbody.html('<div class="block-loader" style="width:100%"></div>');
}
});
$('#submit_with_answer').click(function() {
if ($.trim($('#text-claim').val()).length > 0)
{
$('#complaint_feedback').submit();
}
else
{
$('#textarea-group').addClass('has-error');
$('#answer_error').html('Заполните поле «Добавить текст ответа»');
}
});
};
</script>
The "_show" view is:
<?php $form = ActiveForm::begin([
'id' => 'complaints',
'action' => Url::to(['complaints/show']),
'method' => 'GET',
'options' =>
[
'class' => 'form-respons form-claimadm',
'data-pjax' => 1,
],
]);
active fields....
<div class="form-btns col-md-2 col-sm-6 col-xs-12">
<?= Html::submitButton('Применить', ['class' => 'btn btn-primary','style'=>"float:right;"]) ?>
</div>
</div>
<?php ActiveForm::end(); ?>
and _handle_form is:
<?php
use yii\widgets\ActiveForm;
use yii\helpers\Url;
?>
<?php
$form = ActiveForm::begin([
'id' => 'complaint_feedback',
'action' => Url::to(['complaints/handle-complaint']),
'method' => 'POST',
'options' => ['class' => 'form-respons form-claim-feedback','style'=>'display:none;'],
]);
?>
<div id="textarea-group" class="form-group">
<label for="text-claim" class="hidden-xs">Добавить текст ответа</label>
<textarea class="form-control" id="text-claim" rows="3" name="complaint_answer" placeholder="Добавить текст ответа"></textarea>
<div id="answer_error" class="help-block"></div>
<input id="complaint_id" name="complaint_id" type="hidden" value="">
</div>
<div class="clearfix form-btns">
<button type="button" onclick="$('#complaint_feedback').submit();" class="btn btn-link">Обработать без ответа</button>
<button id="submit_with_answer" type="button" class="btn btn-primary">Отправить</button>
</div>
<?php ActiveForm::end(); ?>
<a id="hide_handle_form" style="display: none;" onclick="$('#complaint_feedback').hide(); $('.handle_button').removeClass('disabled'); $(this).hide();$('tr[data-key='+$('#complaint_id').val()+']').removeClass('row-open');" class="btn btn-link btn-show-hide">Свернуть
</a>
if I comment lines with pjax, everything works correctly. How can I fix this trouble?
I started to learn Laravel (nice framework), and being more and more familiar with it. But I arrive at a point where I don't understand why and how..
I generate a PDF from one of my view. The view is just composed by 3 {!! Form::text , which are filled by Varchar (length:2000) coming from my database.
I well generate the PDF but i can't understand why the text inside goes totally out of the the {!! Form::text in the .pdf-file.
I can't understand why the text stand inside the {!! Form::text for the first lines, but at the last one, the text will go out of the box and keep being writing until it touch the right margin of the pdf, and so diseapper..
I try to play around with {!! Form::text or {!! Form::textarea: same results..
I try to play around with " 'rows' => '15', 'cols' => '100'," parameters: same results...
Does someone might have an idea on why the text doesn't want to stay inside its {!! Form::textarea for description/sentiment and position forms?
My view:
#extends('template')
#section('contenu')
<div class="container">
<div class="jumbotron">
<h2> PTS | <em><strong> Weekly Comments</strong></h2>
<h3><strong>week: {{$week_number}}</strong></h3>
<br>
</div>
#foreach($comments as $comment)
<div class="row">
<div class="panel panel-primary">
<div class="panel-heading" style="text-align:center">
<h3{!! Form::textarea('desk_name', $comment->desk_name, array( 'class'=>'form-control','type' => 'text', 'rows'
=> '5', 'cols' => '5')) !!}</h3>
</div>
</div>
</div>
<br/>
<div class="row">
<div class="col-md-4">
<h3> P&L Weekly | </h3>
{!! Form::textarea('pnl_wtd', $comment->pnl_wtd, array( 'class'=>'form-control','type' => 'text', 'rows' => '5',
'cols' => '5')) !!}
</div>
<div class="col-md-4">
<h3> P&L MTD | </h3>
{!! Form::textarea('pnl_mtd', $comment->pnl_mtd, array('class'=>'form-control','type' => 'text', 'rows' => '5',
'cols' => '5')) !!}
</div>
<div class="col-md-4">
<h3> P&L YTD | </h3>
{!! Form::textarea('pnl_ytd', $comment->pnl_ytd, array( 'class'=>'form-control','type' => 'text', 'rows' => '5',
'cols' => '5')) !!}
</div>
</div>
<br>
<br>
<div class="row">
<div class="panel panel-warning">
<div class="panel-heading" style="text-align:center">
<h3>Past Week Summary</h3>
</div>
<div class="panel-body">
<div class="col-lg-8">
{!! Form::textarea('description', $comment->description, ['class' => 'textarea']) !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-warning">
<div class="panel-heading" style="text-align:center">
<h3>Sentiment</h3>
</div>
<div class="panel-body">
<div class="col-lg-8">
{!! Form::textarea('sentiment', $comment->sentiment, ['class' => 'form-control', 'type' => 'text', 'rows' =>
'100000', 'cols' => '100000']) !!}
</div>
</div>
</div>
</div>
<div class="row">
<div class="panel panel-warning">
<div class="panel-heading" style="text-align:center">
<h3>Positions</h3>
</div>
<br>
</div>
</div>
<div class="container" id="posi">
{!! Form::textarea('position', $comment->position, ['class' => 'form-control', 'style'=>'resize: none']) !!}
</div>
#endforeach
#stop
The function from my controller:
public function pdfWeekly( $week_number ) {
$picuser = Auth::user();
$comments = Comment::where( 'week_number', '=', $week_number )->get();
$flag = 'pdf';
$pdf = PDF::loadView( 'tr.wc.emailPdf', compact(
'picuser',
'flag',
'week_number',
'comments'
) );
$name = "Principale Trading- Week #" . $week_number . ".pdf";
return $pdf->download( $name );
}
Best Regards.
The pdf use native html layouts. So your framework classes and expressions wont work here.
Try making a divv with width 710px and put you data in that div, it won't flow out.
I have a solution for this it is replace input or textarea to a tag like a textarea-to-text before save. I do:
var $html = $('html').clone();
$($html).find('textarea').replaceWith(function () {
$element = $("<textarea-to-text>").text($(this).val());`
$.each(this.attributes, function (i, attribute) {
$element.attr(attribute.name, attribute.value);
});
return $element;
});`
I have my dynamic form using wbraganca widget and kartik file upload inside it. When I open the page, the field was just showing spinner image instead of a textfield and the console display "unrecognized expression: #tcandidateexp-{$i}-prod_per_year_file". The field I want to use as a file upload is "prod_per_year_file". Any help would be appreciate. Thanks.
<?php $form = ActiveForm::begin(['id' => 'dynamic-form', 'options'=>['enctype'=>'multipart/form-data']]); ?>
<div class='row'>
<?php DynamicFormWidget::begin([
'widgetContainer' => 'dynamicform_wrapper', // required: only alphanumeric characters plus "_" [A-Za-z0-9_]
'widgetBody' => '.container-items', // required: css class selector
'widgetItem' => '.item', // required: css class
'limit' => 5, // the maximum times, an element can be added (default 999)
'min' => 1, // 0 or 1 (default 1)
'insertButton' => '.add-item', // css class
'deleteButton' => '.remove-item', // css class
'model' => $models_exp[0],
'formId' => 'dynamic-form',
'formFields' => [
'start_year',
'end_year',
'company',
'prod_per_year',
'prod_per_year_file',
'inc_per_year',
'inc_per_year_file'
],
]); ?>
<div class="panel panel-default" style="width:85%">
<div class="panel-heading">
<h4>
<i class="glyphicon glyphicon-envelope"></i> Experiences
<button type="button" class="add-item btn btn-success btn-sm pull-right"><i class="glyphicon glyphicon-plus"></i> Add</button>
</h4>
</div>
<div class="panel-body">
<div class="container-items"><!-- widgetBody -->
<?php foreach ($models_exp as $i => $model_exp): ?>
<div class="item panel panel-default"><!-- widgetItem -->
<div class="panel-heading">
<h3 class="panel-title pull-left">Detail</h3>
<div class="pull-right">
<button type="button" class="remove-item btn btn-danger btn-xs"><i class="glyphicon glyphicon-minus"></i></button>
</div>
<div class="clearfix"></div>
</div>
<div class="panel-body">
<?php
// necessary for update action.
if (! $model_exp->isNewRecord) {
echo Html::activeHiddenInput($model_exp, "[{$i}]id");
}
?>
<div class="row">
<div class="col-sm-6" >
<?=
$form->field($model_exp, "[{$i}]start_year")->textInput();
?>
</div>
<div class="col-sm-2">
<?=
$form->field($model_exp, "[{$i}]end_year")->textInput();
?>
</div>
<div class="col-sm-2">
<?=
$form->field($model_exp, "[{$i}]company")->textInput();
?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]prod_per_year")->textInput() ?>
</div>
<div class="col-sm-10">
<?php
//$form->field($model_exp, "[{$i}]prod_per_year_file")->textInput()
echo $form->field($model_exp, '[{$i}]prod_per_year_file')->widget(FileInput::classname(), [
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]inc_per_year")->textInput() ?>
</div>
<div class="col-sm-10">
<?= $form->field($model_exp, "[{$i}]inc_per_year_file")->textInput() ?>
</div>
</div><!-- .row -->
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div><!-- .panel -->
<?php DynamicFormWidget::end(); ?>
</div>
Try replace the single quotes with double quotes
echo $form->field($model_exp, "[{$i}]prod_per_year_file")->widget(FileInput::classname(), [
'pluginOptions' => [
'showPreview' => false,
'showCaption' => true,
'showRemove' => true,
'showUpload' => false
]
]);
How do I create a dynamic list of the same form and show it on the view on Yii2 (it can be viewed as a list of the same object with different information) Thanks.
I have the following form on /frontend/views/site/example.php
That form I want to put it on a list.
<div class="site-example">
<h1><?= Html::encode($this->title) ?></h1>
<p>Example of a list:</p>
<div class="row">
<div class="col-lg-5">
<?php $form = ActiveForm::begin(['id' => 'form-example']); ?>
<?= $form->field($model, 'email')->textInput(['readonly' => true, 'value' => $email]) ?>
<?= $form->field($model, 'lastname')->textInput(['readonly' => true, 'value' => $lastname]) ?>
<?= $form->field($model, 'phone')->textInput(['readonly' => true, 'value' => $phone]) ?>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
Assuming this is your controller.
<?php
namespace frontend\controllers;
use Yii;
use yii\base\Model;
use yii\web\Controller;
use frontend\models\YourForm;
class SiteController extends Controller
{
public function actionYourAction()
{
$forms = [new YourForm, new YourForm, new YourForm];
return $this->render('example', [
'forms' => $forms
]);
}
}
Then your view could be below
<div class="site-example">
<h1><?= Html::encode($this->title) ?></h1>
<p>Example of a list:</p>
<div class="row">
<div class="col-lg-5">
<?php foreach ($forms as $index => $form): ?>
<?php $form = ActiveForm::begin(['options' => ['id' => "form-example-$index"]]); ?>
<?= $form->field($form, "[$index]email")->textInput(['readonly' => true, 'value' => $form->email]) ?>
<?= $form->field($form, "[$index]lastname")->textInput(['readonly' => true, 'value' => $form->lastname]) ?>
<?= $form->field($form, "[$index]phone")->textInput(['readonly' => true, 'value' => $form->phone]) ?>
<?php ActiveForm::end(); ?>
<?php endforeach; ?>
</div>
</div>
</div>
I have following code in my model:
public function getData($property)
{
$data = array(
'a_4_1' => array(
'RUB',
'USD',
'JPY',
),
);
return $data[$property];
}
And in my view:
<?= $form->labelEx($model, 'a_4_1', array('class' => 'col-xs-12 col-sm-2 control-label')) ?>
<div class="col-xs-12 col-sm-3">
<?= $form->dropDownList($model, 'a_4_1',$model->getData('d_4_1'), array('class' => 'form-control')) ?>
<?= $form->error($model, 'a_4_1') ?>
</div>
When I save it to the database, it saves data in the integer format (e.g 1,2,..)
I need to save array elements' names to the database(e.g RUB, USD)(not integer numbers). How can I do it?
use array_combine() to change key value of your array like below:
array_combine($model->getData('d_4_1'),$model->getData('d_4_1'))
<?= $form->labelEx($model, 'a_4_1', array('class' => 'col-xs-12 col-sm-2 control-label')) ?>
<div class="col-xs-12 col-sm-3">
<?= $form->dropDownList($model, 'a_4_1',array_combine($model->getData('d_4_1'),$model->getData('d_4_1')), array('class' => 'form-control')) ?>
<?= $form->error($model, 'a_4_1') ?>
</div>