I'm using 2amigos datepicker in my application and it's working good throughout. Today I tried to apply AdminLTE theme to the application. I've added all the css, js in the asset file and uploaded them in the respective folders. No error in the browser console so far.
The first thing I notice is that the datepicker is not working. When I click on the calendar icon on the datepicker, the datepicker doesn't open.
Asset file
<?php
namespace frontend\assets;
use yii\web\AssetBundle;
/**
* Main frontend application asset bundle.
*/
class DashboardAsset extends AssetBundle
{
public $basePath = '#webroot';
public $baseUrl = '#web';
public $css = [
'css/site.css',
'css/bootstrap.min.css',
'css/font-awesome.min.css',
'https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css',
'css/AdminLTE.min.css',
'css/skins/_all-skins.min.css',
'plugins/iCheck/flat/blue.css',
'plugins/morris/morris.css',
'plugins/jvectormap/jquery-jvectormap-1.2.2.css',
'plugins/datepicker/datepicker3.css',
'plugins/daterangepicker/daterangepicker.css',
'plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css',
];
public $js = [
'js/bootstrap/bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js',
'plugins/morris/morris.min.js',
'plugins/sparkline/jquery.sparkline.min.js',
'plugins/jvectormap/jquery-jvectormap-1.2.2.min.js',
'plugins/jvectormap/jquery-jvectormap-world-mill-en.js',
'plugins/knob/jquery.knob.js',
'https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js',
'plugins/daterangepicker/daterangepicker.js',
'plugins/datepicker/bootstrap-datepicker.js',
'plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js',
'plugins/slimScroll/jquery.slimscroll.min.js',
'plugins/fastclick/fastclick.js',
'js/app.min.js',
'js/dashboard.js',
'js/demo.js',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}
I'm using the datepicker like below -
use dosamigos\datepicker\DatePicker;
<?= $form->field($model1, 'startdate')->widget(
DatePicker::className(), [
'options' => ['placeholder' => 'Start Date ...', 'id' => 'startdate1'],
'inline' => false,
style="background-color: #fff; width:250px">{input}</div>',
'clientOptions' => [
'autoclose' => true,
'todayHighlight' => true,
'format' => 'yyyy-mm-dd'
]
]);?>
Related
I extended "dektrium/yii2-user" controller's class as below, now I want to have $authItems in render view file of parent class, how should I pass this variable?
namespace app\controllers;
use app\models\AuthItem;
use dektrium\user\controllers\RegistrationController as BaseRegistrationController;
class RegistrationController extends BaseRegistrationController
{
public function actionRegister()
{
$authItems = AuthItem::find()->all();
return parent::actionRegister();
}
}
its is main class method
public function actionRegister()
{
if (!$this->module->enableRegistration) {
throw new NotFoundHttpException();
}
/** #var RegistrationForm $model */
$model = \Yii::createObject(RegistrationForm::className());
$event = $this->getFormEvent($model);
$this->trigger(self::EVENT_BEFORE_REGISTER, $event);
$this->performAjaxValidation($model);
if ($model->load(\Yii::$app->request->post()) && $model->register()) {
$this->trigger(self::EVENT_AFTER_REGISTER, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Your account has been created'),
'module' => $this->module,
]);
}
return $this->render('register', [
'model' => $model,
'module' => $this->module,
]);
}
A solution could be
don't invoke the parent::actionRegister();
and add the code directly in your actionRegister
and last add the autItems to the render function array parameters
class RegistrationController extends BaseRegistrationController
{
public function actionRegister()
{
$authItems = AuthItem::find()->all();
// return parent::actionRegister();
if (!$this->module->enableRegistration) {
throw new NotFoundHttpException();
}
/** #var RegistrationForm $model */
$model = \Yii::createObject(RegistrationForm::className());
$event = $this->getFormEvent($model);
$this->trigger(self::EVENT_BEFORE_REGISTER, $event);
$this->performAjaxValidation($model);
if ($model->load(\Yii::$app->request->post()) && $model->register()) {
$this->trigger(self::EVENT_AFTER_REGISTER, $event);
return $this->render('/message', [
'title' => \Yii::t('user', 'Your account has been created'),
'module' => $this->module,
]);
}
return $this->render('register', [
'model' => $model,
'module' => $this->module,
'authItems' => $authItems;
]);
}
}
I would do something like this:
Add a member variable to your extended class, such as:
namespace app\controllers;
use app\models\AuthItem;
use dektrium\user\controllers\RegistrationController as BaseRegistrationController;
class RegistrationController extends BaseRegistrationController
{
public $authitems;
public function actionRegister()
{
$this->authitems = AuthItem::find()->all();
return parent::actionRegister();
}
}
Then in your parent class, do a test to see if that variable is set, such as:
public function actionRegister()
{
//.........
return $this->render('register', [
'model' => $model,
'module' => $this->module,
'authitems' => (isset($this->authitems)) ? $this->authitems : null;
]);
}
I have this code in my view
<div class="col-xs-6">
<?php echo $form->field($model, 'deskripsi_produk')->widget(Redactor::className(),['clientOptions'=>['autoresize'=>'true', 'limiter' => 20, 'plugins' => ['limiter'], 'buttons'=> ['html', 'formatting', 'bold', 'italic','underline','lists','horizontalrule'],]]);?>
</div>
it can limit 20 char but How I can limit text area to max string defined on model instead of limit with specific number?
Here is my model
class TbProduk extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public $image;
public static function tableName()
{
return 'tb_produk';
}
public function rules()
{
return [
...
[['deskripsi_produk'], 'string', 'max' => 2000],
[['deskripsi_produk'], 'checkDesc'],
...
];
}
}
Trying to get the value via rules is a terrible idea. Instead you should create a constant in TbProduk that will hold the length:
class TbProduk extends \yii\db\ActiveRecord
{
const DESKRIPSI_PRODUK_LENGTH = 2000;
...
public function rules()
{
return [
...
[['deskripsi_produk'], 'string', 'max' => static::DESKRIPSI_PRODUK_LENGTH],
...
];
}
}
And in your view:
<div class="col-xs-6">
<?php echo $form->field($model, 'deskripsi_produk')->widget(Redactor::className(),['clientOptions'=>['autoresize'=>'true', 'limiter' => TbProduk::DESKRIPSI_PRODUK_LENGTH, 'plugins' => ['limiter'], 'buttons'=> ['html', 'formatting', 'bold', 'italic','underline','lists','horizontalrule'],]]);?>
</div>
I have created custom model for my report.Here i have declared two variables fy_yr and fy_qtr.In my report form ,i have two combo boxes and I have to generate my report according to values from my combo boxes.But my problem is the selected values from combos are not set in my custom model.What is the problem?
My report view code:
<?php $form = ActiveForm::begin(['id' => 'member-report',
'action' => ['member-report'],
'method' => 'post',
]); ?>
<table border="1" class="table-bordered">
<tr>
<td style="margin-right:20px;">
<?= $form->field($model, 'fy_yr')->dropDownList(
ArrayHelper::map(FiscalYear::getAllFiscalYr(),'fy_id','fiscal_yr'),
['prompt'=>'Select Fiscal Year.']
)
?>
</td>
<td>
<?= $form->field($model, 'fy_qtr')->dropDownList(
ArrayHelper::map(CodeValue::getFiscalYrQuater(),'cv_id','cv_lbl'),
['prompt'=>'Select Quarter.']
)
?>
</td>
<td><input type="submit" value="Search" class="btn btn-primary btn-block btn-flat"/></td>
<td><input type="submit" value="Print" class="btn btn-primary btn-block btn-flatb"/></td>
</tr>
</table>
<?php ActiveForm::end(); ?>
My model is:
class SfclReport extends Model
{
public $fy_yr;
public $fy_qtr;
public function rules()
{
return [
[['fy_id', 'fy_qtr'], 'required'],
];
}
}
and my controller is
public function actionMemberReport()
{
$model = new SfclReport;
if ($model->load(Yii::$app->request->post())) {
}
return $this->render('member_report',['model'=>$model]);
}
add fy_yr and Specify your variable datatype
class SfclReport extends Model
{
public $fy_yr;
public $fy_qtr;
public function rules()
{
return [
[['fy_id', 'fy_qtr'], 'required'],
[['fy_id',], 'integer'],
[['fy_yr','fy_qtr'], 'string'],
];
}
}
i have searched all over for a solution and tried many of the advises that was given (just saying if you think I'm too lazy)
I'm a bit of a Kendo noob, so not sure what I'm missing?
As the title say, I got a grid of items and want to edit them inline. all works fine, but it seems that my editor template just get ignored and 2 inputs get shown when in edit mode (since the child object that must be selected is a complex object with Id and Name properties)
ps: sorry bout formatting. seems my browser don't show this windows toolbar?
Kendo MVC Grid
Html.Kendo().Grid<MyViewModel>()
.Name("Grid")
.Columns(columns =>
{
columns.Bound(o => o.Id).Hidden(true);
columns.Bound(o => o.Product).EditorTemplateName("ProductsListTemplate");
...other columns
columns.Command(command =>
{
command.Edit();
command.Destroy();
}).Width(180);
})
.AutoBind(true)
.ToolBar(toolbar => toolbar.Create())
.Editable(editable => editable.Mode(GridEditMode.InLine).Enabled(true))
.Filterable(ftb => ftb.Mode(GridFilterMode.Row))
.Resizable(resize => resize.Columns(true))
.Selectable(sel => sel.Mode(GridSelectionMode.Single)
.Enabled(true))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(20)
.Events(events => events.Error("error_handler"))
.Model(model =>
{
model.Id(c => c.Id);
model.Field(c => c.Product).Editable(true);
...other fields...
})
.Create(update => update.Action("Create", "MyController"))
.Read(read => read.Action("Read", "MyController"))
.Update(update => update.Action("Edit", "MyController"))
.Destroy(update => update.Action("Delete", "MyController"))
))
ProductsListTemplate.cshtml (in Shared/EditorTemplates, product options are present in the viewdata as IEnumerable )
#(Html.Kendo().DropDownList()
.Name("MyChildViewModel")
.DataValueField("Id")
.DataTextField("Name")
.BindTo((IEnumerable) ViewData["ProductOptions"])
)
MyViewModel
public class MyViewModel
{
public int Id { get; set; }
[Display(Name = "Product")]
[UIHint("ProductsListTemplate")]
public MyChildViewModelProduct { get; set; }
... other properties
public class MyChildViewModel
{
public string Id { get; set; }
public string Name { get; set; }
}
I've been struggling with the Kendo dropdownlist for 2 days now and just can't seem to get it configured correctly.
How do I get the Kendo Dropdownlist to show the current item of the #Model? This is my code:
#Html.TextBoxFor(model => model.ShortDescription, new { #class="wide200;" })
#(Html.Kendo().DropDownList()
.Name("importance")
.HtmlAttributes(new { style = "width: 250px" })
.DataTextField("Name")
.DataValueField("ID")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetImportanceList", "Home");
})
.ServerFiltering(true);
})
.SelectedIndex(0)
)
And in my controller:
public ActionResult GetImportanceList()
{
GenericRepository<Importance> _repository = new GenericRepository<Importance>(_context);
IEnumerable<ImportanceViewModel> list = _repository.Get().ConvertToViewModelList();
return Json(list, JsonRequestBehavior.AllowGet);
}
Problem is with SelectedIndex(0) which is set to the first item. How can I set it to whatever is in the model? It's very simple to do for the textbox (first line in the code): model => model.ShortDescription. But how does this work for the dropdownlist?
I don't just want to set it upon the showing of the editor, but also want the grid to know what the new selection is after I click the Update button.
Note that this is in a custom template for the grid popup editor.
Try this,
You have to pass DropDownListId in model and ListItems.
#(Html.Kendo().DropDownListFor(m=>m.DropDownListId)
.Name("importance")
.HtmlAttributes(new { style = "width: 250px" })
.DataTextField("Name")
.DataValueField("ID")
.DataSource(source => {
source.Read(read =>
{
read.Action("GetImportanceList", "Home");
})
.ServerFiltering(true);
})
.SelectedIndex(0)
)
I asked this question to Telerik. Apparently the Name mustn't be assigned.