How do I set customized placeholder in 'booster.widgets.TbActiveForm'? - yii

I use like this..
<div class="row">
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
But there is default placeholder 'Email Address'. How I want to set there my own placeholder ?

you can add html options as below:
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
'widgetOptions' => array(
'htmlOptions' => array(
'placeholder' => 'my placeholder'
)
)
)
);
?>
for more detail have a look at Booster active form

Related

Onsubmit call function in yii

I want to call function when submit form in yii. In my form I enabled validateOnSubmit.
when in call function form Onsubmit mean it will call function in twice.
My Coding,
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'question-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => true,
'enableClientValidation' => false,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange' => false,
),
'htmlOptions' => array('onsubmit' => 'return checkmultiple()',),
));
?>
<div class="form-group">
<?php echo $form->labelEx($model, 'question_title'); ?>
<?php echo $form->textField($model, 'question_title', array('size' => 50, 'maxlength' => 250, 'class' => 'form-control')); ?>
<?php echo $form->error($model, 'question_title'); ?>
</div>
<?php if ($tileAssigned == Yii::app()->const->FLAG_ZERO) { ?>
<div class="form-group">
<?php echo $form->labelEx($model, 'type', array('label' => 'Is Multiple Choice')); ?>
<?php echo $form->radioButtonList($model, 'type', $yesnoList, array('separator' => '', 'onchange' => 'questionTypeChange(this.value);', 'class' => '')); ?>
<?php echo $form->error($model, 'type'); ?>
</div>
I am calling function checkmultiple mean it will call twice.
function checkmultiple()
{
}

yii CListView relation sorting

Currently when i click on sort by in CListView generated table, it adds MODEL_NAME_2 to the url
?page=1&sort=MODEL_NAME_2.cat.desc
is there a way to remove it? or maybe rename it to something else? Or is this just how Yii works?
here is my actionIndex() in my controller
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('MODEL_NAME_1', array(
'id'=> '',
'criteria' => array(
'with' => 'MODEL_NAME_2',
'together'=>true, //specifies whether the query should be run using a join
),
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'MODEL_NAME_2.cat'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),
'pagination'=>array(
'pageVar'=>'page'
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
in my view
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view', // refers to the partial view named '_view'
'enableHistory'=> true,
'sortableAttributes' => array('MODEL_NAME_2.cat'=>'Make'),
'pagerCssClass' => 'pagination',
'loadingCssClass' => '', //remove loading icon
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>',
));
ideally i would like my url to look like this
mysite.com/bla/page/2/sort/cat/desc
basically using alot of / and no ? or &
In ListView definition change:
'sortableAttributes' => array('make'=>'Make'),
In your dataProvider
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'make'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),

How to show timepicker based jqrelcopy yii?

How to show timepicker based yiibooster, with Jqrelcopy.
I've code like this :
<div class="control-group "><label class="control-label required">Jam Kerja</label>
<div class="controls">
<a id="copylink" href="#" rel=".copy">Tambah Jam Kerja / Shift</a>
<div class="row copy">
<?php echo CHtml::label('',''); ?>
<?php $this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'htmlOptions'=>array('width'=>'50px'),
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
),
)
);
?>
<?php
$this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
)
)
);
?>
</div>
</div>
</div>
When I add new, Timepicker always on field 1. Can't on field changed.

CJuiDialog not closing in Ajax success

Im trying to close CJuiDialog in Ajax success but its not closing, only iframe contents gets cleared popup not closing,
CJuiDialog Coding:
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'Document-Edit',
'options'=>array(
'title'=>'Manage Documents',
'autoOpen'=>false,
'modal'=>true,
'width'=>800,
'height'=>600,
// 'close'=>'js:function(e,o){location.reload();}' ,
),
));
?>
<iframe id="cru-frame-doc" width="100%" height="100%" frameBorder="0" scrolling="no" >
<?php $this->renderPartial('ManageDocuments_Update', array('model'=>$model)); ?>
</iframe>
<?php $this->endWidget();?>
CGridView Code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'document-grid',
'dataProvider'=>$model->search(),
'columns'=>array(
array(
'class' => 'CButtonColumn',
'template' => '{DocumentEdit}',
'buttons' => array(
'DocumentEdit' => array(
'imageUrl'=>Yii::app()->request->baseUrl.'/images/update.png',
'url'=>'$this->grid->controller->createUrl("DocumentEdit", array("id"=>$data->crm_document_id,"asDialog"=>1))',
'click'=>'function(){
$("#cru-frame-doc").attr("src",$(this).attr("href")); $("#Document-Edit").dialog("open"); return false;}',
),
),),
'crm_document_id',
'name',
'doc_type',
'delivery_method',
'content_subject',
'content_body',
'is_active',
),
)); ?>
Ajax Submit Button Code:
<?php
echo CHtml::ajaxSubmitButton( 'Save',
'js:document.location.href='.'"'.Yii::app()->createUrl("baseContact/SaveManageDocuments_Update",array("id" => $model->crm_document_id)).'"',
array(
'type'=>'POST',
"dataType" => "json",
'success' => 'function(data){
if(data.result=="success"){
window.parent.$("#Document-Edit").dialog("close");
window.parent.$("#cru-frame-doc").attr("src","");
}
}',
));
?>
Can anyone point out where im making error...
Use the below code in SaveManageDocuments_Update Controller action to close the dialog,
echo CHtml::script("window.parent.$('#Document-Edit').dialog('close');window.parent.$('#cru-frame-doc').attr('src',''); window.parent.$.fn.yiiGridView.update('document-grid');");
Yii::app()->end();

Validation fails on dropdown list input item

Friends,
I have a registration form with several items and the drop down list on these items seems like its not being picked up by the form submission.
The View:
</div>
<div class="row">
<?php echo CHtml::activeLabel($model, 'Gjinia'); ?>
<?php echo CHtml::dropDownList('sex', 0, $data = array(0 => 'Mashkull', 1 => 'Femer'))
?>
</div>
<div class="row">
<?php echo CHtml::activeLabel($model, 'Arsimimi'); ?>
<?php echo CHtml::dropDownList('education', 0, $data = array(0 => 'Ulet', 1 => 'Mesem', 2 => 'Larte')) ?>
</div>
<div class="row">
<?php echo CHtml::activeLabel($model, 'Statusi Martesor'); ?>
<?php echo CHtml::dropDownList('marital_status', 0, $data = array(0 => 'Beqar/e', 1 => 'I/E divorcuar', 2 => 'I/E martuar', 3 => 'I/E veje')) ?>
</div>
Validation rules:
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('name, lastname, sex, education,
marital_status, employment,
dob, municipality, address,
cell_no, email, initialPassword,
repeatPassword', 'required'),
array('sex, employment, municipality,', 'numerical', 'integerOnly' => true),
array('email, initialPassword, repeatPassword, name, lastname', 'length', 'max' => 100),
array('initialPassword, repeatPassword', 'required', 'on' => 'insert'),
array('initialPassword, repeatPassword', 'length', 'min' => 6, 'max' => 40),
array('initialPassword', 'compare', 'compareAttribute' => 'repeatPassword'),
);
}
After submitting my form I am getting the following when I do a print_r on $_POST['Auser']:
Array ( [name] => Name [lastname] => Lname [address] => B ellit
[cell_no] => 044 568 178 [email] => gzzi#gmail.com [id] => [sex] =>
[education] => [marital_status] => [employment] => [industry] => [dob] =>
[municipality] => [password] => )
and the error message:
Sex cannot be blank.
Education cannot be blank.
Marital Status cannot be blank.
Employment cannot be blank.
Dob cannot be blank.
Municipality cannot be blank.
Your dropdownlist should be defined like this:
<div class="row">
<?php echo CHtml::activeLabel($model, 'Statusi Martesor'); ?>
<?php echo CHtml::activeDropDownList($model, 'marital_status', array(0 => 'Beqar/e', 1 => 'I/E divorcuar', 2 => 'I/E martuar', 3 => 'I/E veje')) ?>
</div>
Instead of:
<div class="row">
<?php echo CHtml::activeLabel($model, 'Statusi Martesor'); ?>
<?php echo CHtml::dropDownList('marital_status', 0, $data = array(0 => 'Beqar/e', 1 => 'I/E divorcuar', 2 => 'I/E martuar', 3 => 'I/E veje')) ?>
</div>
In the first instance (where I used CHtml::activeDropDownList($model, 'attribute_name')), you can access your dropdown attributes after doing $model->attributes = $_POST['ModelName']; like this $model->sex, $model->marital_status because the POST array is ging to be like: $_POST['ModelName']['sex'], $_POST['ModelName']['marital_status']
When you use CHtml::dropDownList('field_name', 'selected_value', array('option1', 'option2')), the POST array is of the form $_POST['field_name'] and for ActiveRecord, what you want is $_POST['ModelName']['field_name']
I hope that solves your question.