iam using clevertech an extension for YII, dose anybody know how i can add my own custom placeholder text inside the input.
Below is an example of the input filed:
<?php echo $form->textFieldGroup(
$model,
'textField',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.'
)
); ?>
You can add placeholder to you html attributes, as follows:
<?php echo $form->textFieldGroup(
$model,
'textField',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.',
'widgetOptions' => array(
'options' => array(
'placeholder' => 'Placeholder content',
),
),
)
); ?>
See http://yiibooster.clevertech.biz/widgets/forms/view/activeform.html
Try this...
<?php echo $form->textFieldGroup(
$model,
'textField',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions'=>array(
'htmlOptions'=>array('placeholder' => 'Placeholder content')
)
'hint' => 'In addition to freeform text, any HTML5 text-based input appears like so.'
)
); ?>
Related
I'm trying to change a column name of CGridView.
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'package-days-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
'package_id',
'description',
array(
'name' => 'My description',
'value' => 'description'
),
array(
'class' => 'CButtonColumn',
),
),
));
?>
I need to add title 'My description' to 'description' column but I'm getting this error
Property "PackageDays.My description" is not defined.
Seems you want change the header not the name try this way
'header'=>'My description',
<?php
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'package-days-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'id',
'package_id',
'description',
array(
'name' => 'description',
'header' = => 'My Description',
// 'value' => 'description' don't need no more
),
array(
'class' => 'CButtonColumn',
),
),
));
?>
I just learning Yiibooster recently and stuck with this..
I have a dependent dropdownlistgroup using yii booster with ajax so kelas data will be generated after matkul selected. It works fine if i using dropdownlist from yii but i want a nice form using Yiibooster form.
<?php
echo $form->dropDownListGroup(
$model,
'matkul',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'data' => $matkullist,
'htmlOptions' => array('multiple' => false),
),
'prompt'=>'Select',
array(
'ajax'=> array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Kp/Getkelas'), //url to call.
'update'=>'#'.CHtml::activeId($model,'kelas'), //selector to update
)
)
)
); ?>
<?php echo $form->dropDownListGroup(
$model,
'kelas',
array(
'wrapperHtmlOptions' => array(
'class' => 'col-sm-5',
),
'widgetOptions' => array(
'htmlOptions' => array('multiple' => false),
)
)
);?>
The problem is the ajax does not work when i use dropdownlistgroup, when i test it with normal dropdownlist like below code its work normal, sorry for my english.
echo CHtml::dropDownList('country_id','', array(1=>'USA',2=>'France',3=>'Japan'),
array(
'ajax' => array(
'type'=>'POST', //request type
'url'=>CController::createUrl('Kp/Getkelas'), //url to call.
'update'=>'#city_id', //selector to update
)));
echo CHtml::dropDownList('city_id','', array());
I'm not hear about the function dropdownListGroup.
using Yiibooster, you can add the dropdown as,
$this->widget(
'booster.widgets.TbSelect2',
array(
'asDropDownList' => false,
'name' => 'clevertech',
'options' => array(
'tags' => array('clever', 'is', 'better', 'clevertech'),
'placeholder' => 'type clever, or is, or just type!',
'width' => '40%',
'tokenSeparators' => array(',', ' ')
)
)
);
ref link : http://yiibooster.clevertech.biz/widgets/forms_inputs/view/select2.html
You should put ajax options in widgetOptions -> htmlOptions -> ajax
$form->dropDownListGroup($model, 'beer', array(
'widgetOptions' => array(
'data' => CHtml::listData(Beer::model()->findAll(), 'id', 'name'),
'htmlOptions' => array(
'ajax' => array(
'type' => 'POST',
'url' => Yii::app()->createUrl('/beer'),
'update' => '#beer',
)
),
)
);
not most efficient solution but it works,
looking the html at the end, we have
<div class="form-group">
<?php echo $form->labelEx($model,'matkul',array('class' => 'col-sm-3 control-label')); ?>
<div class="col-sm-5 col-sm-9">
<?php echo $form->dropDownList($model,'matkul',$matkullist รณ array(),
array('class' => 'form-control','ajax'=>array('type'=>'POST','url'=>CController::createUrl('Kp/Getkelas'),'update'=>'#'.CHtml::activeId($model,'kelas')),'empty'=>'Select')); ?>
<?php echo $form->error($model,'matkul'); ?>
</div>
</div>
important is that 'class' put the html class, 'class' => 'col-sm-3 control-label' and 'class' => 'form-control', for dropDownList
i want to show already selected values in tags of ESelected extension but unable to find any solution my code in update form in view is
$this->widget('ext.select2.ESelect2', array(
'name' => 'cat_names[]',
'data' => Coupon::getCategories(),
'options' => array(
'placeholder' => '',
'allowClear' => true,
),
'htmlOptions' => array(
'multiple' => 'multiple',
),
));
if i add tags fields in option of Eselect it changes the behaviour and stop working i add tags in options like this
'tags' => Coupon::getCategories_old(),
Any suggestion will be helpfull thanks in advance
$this->widget('ext.select2.ESelect2', array(
'name' => 'cat_names[]',
'value'=> array(91,95),
'data' => Coupon::getCategories(),
'options' => array(
'placeholder' => '',
'allowClear' => true,
),
'htmlOptions' => array(
'multiple' => 'multiple',
),
));
Hi I'm using the test code from http://www.yiiframework.com/doc/api/1.1/CMenu
$this->widget('zii.widgets.CMenu', array(
'items'=>array(
// Important: you need to specify url as 'controller/action',
// not just as 'controller' even if default acion is used.
array('label'=>'Home', 'url'=>array('site/index')),
// 'Products' menu item will be selected no matter which tag parameter value is since it's not specified.
array('label'=>'Products', 'url'=>array('product/index'), 'items'=>array(
array('label'=>'New Arrivals', 'url'=>array('product/new', 'tag'=>'new')),
array('label'=>'Most Popular', 'url'=>array('product/index', 'tag'=>'popular')),
)),
array('label'=>'Login', 'url'=>array('site/login'), 'visible'=>Yii::app()->user->isGuest),
),
));
Other test code such as zii.widgets.jui.CJuiAutoComplete and zii.widgets.jui.CJuiDraggable work fine in my Yii view...
The CMenu code snippet just shows the links as a hierarchical list.
When using a div with an id of mainmenu things seem to improve a bit... then I tried using a lot of nested arrays:
http://sky-walker.net/temp/test/yii/testnews/index.php?r=site/test
It supports array nesting of 5+ levels deep...
But if I highlight/select it all (to display the white menu links) it doesn't display the hierarchy nicely...
I was wondering if it could be a popup menu that gradually shows children if the parents are hovered over?
I also tried disabling the div with id of mainmenu from the layout's main.php.
ok, after seeing what you have, follow my example:
<div id="mainmenu">
<?php
$this->widget('zii.widgets.CMenu', array(
'items' => array(
array('label' => 'linkbook', 'url' => array('/site/index')),
array('label' => 'About', 'url' => array('/site/page', 'view' => 'about')),
array('label' => 'Contact', 'url' => array('/site/contact')),
array('label' => 'Suggest Website', 'url' => array('/websiteSuggest/index'),'visible' => !Yii::app()->user->isGuest),
array('label' => 'Servers', 'url' => array('/server/index'),'visible' => !Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->loginUrl, 'label' => Yii::app()->getModule('user')->t("Login"), 'visible' => Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->registrationUrl, 'label' => Yii::app()->getModule('user')->t("Register"), 'visible' => Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->profileUrl, 'label' => Yii::app()->getModule('user')->t("Profile"), 'visible' => !Yii::app()->user->isGuest),
array('url' => Yii::app()->getModule('user')->logoutUrl, 'label' => Yii::app()->getModule('user')->t("Logout") . ' (' . Yii::app()->user->name . ')', 'visible' => !Yii::app()->user->isGuest),
),
));
?>
</div><!-- mainmenu -->
<br/>
<div id="mainmenu">
<?php
$this->widget('zii.widgets.CMenu', array(
'items' => array(
array('label' => 'Website', 'url' => array('/website/index'), 'visible' => !Yii::app()->user->isGuest),
array('label' => 'Url', 'url' => array('/url/index'), 'visible' => !Yii::app()->user->isGuest),
array('label' => 'Pattern Url', 'url' => array('/patternUrl/index'), 'visible' => !Yii::app()->user->isGuest),
),
));
?>
</div>
I'm using the MbMenu Yii extension now...
http://www.yiiframework.com/extension/mbmenu
It is very easy to install and use and it seems the input array from CMenu can be reused with it (as well as the CssMenu Yii extension)...
It is at the bottom of:
http://sky-walker.net/temp/test/yii/testnews/index.php?r=site/test
I am currently playing around with ZF2 beta 4 and I seem to be stuck when i try to use fieldsets within a form and getting the data back into the form when the form is submitted. I am not sure if I am not setting the input filters right for fieldsets or I am missing something. For example, I have the following (simplified to make it clear):
Controller
public function indexAction(){
$form = new MyForm();
$request = $this->getRequest();
if ($request->isPost()) {
$form->setData($request->post());
if ($form->isValid()) {
//Do something
print_r($form->getData()); //for debug
}
}
return array('form' => $form);
}
MyForm.php
class MyForm extends Form
{
public function __construct()
{
parent::__construct();
$this->setName('myForm');
$this->setAttribute('method', 'post');
$this->add(array(
'name' => 'title',
'attributes' => array(
'type' => 'text',
'label' => 'Title',
),
));
$this->add(new MyFieldset('myfieldset'));
//setting InputFilters here
$inputFilter = new InputFilter();
$factory = new InputFactory();
$inputFilter->add($factory->createInput(array(
'name' => 'title',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
)));
//Now add fieldset Input filter
foreach($this->getFieldsets() as $fieldset){
$fieldsetInputFilter = $factory->createInputFilter($fieldset->getInputFilterSpecification());
$inputFilter->add($fieldsetInputFilter,$fieldset->getName());
}
//Set InputFilter
$this->setInputFilter($inputFilter);
}
}
MyFieldset.php
class MyFieldset extends Fieldset implements InputFilterProviderInterface{
public function __construct($name)
{
parent::__construct($name);
$factory = new Factory();
$this->add($factory->createElement(array(
'name' => $name . 'foo',
'attributes' => array(
'type' => 'text',
'label' => 'Foo',
),
)));
}
public function getInputFilterSpecification(){
return array(
'foo' => array(
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
),
);
}
}
I am able to output the form as expected and I end up with two input elements named 'title' and 'myfieldsetfoo' (the name given when outputing with the ViewHelper). So of course when I submit the raw post will show values for 'title' and 'myfieldsetfoo'. However, when I use SetData() the values for the field set are not being populated (although I can see the values in the raw post object). Instead, examining the output of '$form->getData()' I receive:
Array(
[title] => Test,
[myfieldset] => Array(
[foo] =>
)
)
What am I missing? What do I need to do so that ZF2 understands how to populate the fieldset?
Thanks for any help, this is driving me crazy.
Why I do is concatenate InputFilter so I could handle the whole HTML form array posted.
<form method="POST">
<input type="text" name="main[name]" />
<input type="text" name="main[location]" />
<input type="text" name="contact[telephone]" />
<input type="submit" value="Send" />
</form>
This will create an array posted like
post["main"]["name"]
post["main"]["location"]
post["contact"]["telephone"]
Filtered and validated with:
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\Factory as InputFactory;
$post = $this->request->getPost();
$inputFilter = new InputFilter();
$factory = new InputFactory();
// $post["main"]
$mainFilter = new InputFilter();
$mainFilter->add($factory->createInput(array(
'name' => 'name',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));
$mainFilter->add($factory->createInput(array(
'name' => 'location',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));
$inputFilter->add($mainFilter, "main");
// $post["contact"]
$contactFilter = new InputFilter();
$contactFilter->add($factory->createInput(array(
'name' => 'name',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 100,
),
),
),
)));
$contactFilter->add($mainFilter, "contact");
//Set posted data to InputFilter
$inputFilter->setData($post->toArray());
http://www.unexpectedit.com/zf2/inputfilter-validate-and-filter-a-form-data-with-fieldsets
I think you forgot to prepare your form in the controller:
return array('form' => $form->prepare());
This will rename the "name" field of your fieldset to "myfieldset[foo]", so you don't have to prepend the fieldsets name on your own.
Just use
'name' => 'foo'
instead of
'name' => $name . 'foo'
in your fieldset class.
I think the problem is that you declare a new form in your controller. And that clear the previous form.
$form = new MyForm();
I use the Service Manager to declare the form and filters.
And then in the controller I do:
$form = $this->getServiceLocator()->get('my_form');
That way I always get the object I want
Update
I no longer use service manager to call forms. I just call a new form and issue $form->setData($data);
The source for the data can also be entity though then I would issue: $form->bind($entity)