Yii bootstrap widgets TbDatePicker not hiding after select a date.
<?php
echo $form->labelEx($modelRenterStatus,'moving_date');
$this->widget('bootstrap.widgets.TbDatePicker', array(
'model' => $modelRenterStatus,
'attribute' => 'moving_date',
'options' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
'autoclose' => true,
),
));
?>
what's wrong with my this code?
According to YB Docs Options are
options for the original library. This value will be JSON-encoded and
fed to bootstrap-datepicker
And looking into library docs here I can't see the options you have put and so they are invalid.
Taking example from YB site
$this->widget(
'bootstrap.widgets.TbDatePicker',
array(
'name' => 'some_date_jap',
'options' => array(
'language' => 'ja'
))
);
language is option in original library. So recheck it again!
Just to expand my answer here is one that works with my form
<?php
echo $form->datepickerRow($model, 'mode_attribute_here',array('hint'=>'',
'prepend'=>'<i class="icon-calendar"></i>',
'options'=>array('format' => 'yyyy-mm-dd' , 'weekStart'=> 1)
)); ?>
maybe it help others!!
More detail here
<?php
echo $form->labelEx($modelRenterStatus,'moving_date');
$this->widget('bootstrap.widgets.TbDatePicker', array(
'model' => $modelRenterStatus,
'attribute' => 'moving_date',
'options' => array(
'size' => '10', // textField size
'maxlength' => '10', // textField maxlength
'autoclose' => true,
),
));
?>
Related
I'm so beginner in Prestashop 1.7, I wanted to add a dropdown select section in my banner module to select the way to open the banner link.
but the selected value is never passed to the HTML, the code below IS passed but the one under isn't, can you please assist me?
[enter image description here][1]
array(
'type' => 'text',
'lang' => true,
'label' => $this->trans('Banner description', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_DESC',
'desc' => $this->trans('Please enter a short but meaningful description for the banner.', array(), 'Modules.Banner.Admin')
)
array(
'type' => 'select', //select
'lang' => true,
'label' => $this->trans('Banner tab', array(), 'Modules.Banner.Admin'),
'name' => 'BANNER_TAB',
'required'=>'true',
'options' => array(
'query' => array(
array('key' => '_blank', 'name' => 'New tab'),
array('key' => '_self', 'name' => 'Same tab'),
),
'id' => 'key',
'name' => 'name'
),
'desc' => $this->trans('Please select the way to open the link.', array(), 'Modules.Banner.Admin')
)
This is how it looks in the Backoffice:
Here
You not only need to add a new field to your form but also handle saving the data from it.
Take a look at a few examples:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L122
Notice how the module author managed to save each configuration field from the form. This is what you need to do.
If you want to have access to data in your view, you have to pass it:
https://github.com/PrestaShop/ps_featuredproducts/blob/dev/ps_featuredproducts.php#L244
Maybe after you added a new field, you forgot to handle the saving + passing to the view?
I am attempting to create several radio buttons with a specific label...
I am using the following code, however, there is no label
echo $this->Form->radio('qualify', [['value' => 1, 'text' => 'Yes'], ['value' => 0, 'text' => 'No']], ['label' => 'Qualify Only']);
Any ideas on how I can get the label to show up for these radio buttons?
<?php
$qualify = [['value'=>'0','text'=>'No'],['value'=>'1','text'=>'Yes']];
echo $this->Form->input('qualify', array(
'options' => $qualify,
'type' => 'radio',
'placeholder' => 'Qualify Only'
));
?>
This code will be able to pick any existing value in the edit view.
You can still use the $this->Form->input and put a type whether its a select or radio
<?php
$qualify = ['0' => 'No', '1' => 'Yes'];
echo $this->Form->input('qualify', array(
'options' => $qualify,
'type' => 'radio',
'placeholder' => 'Qualify Only'
));
?>
there are 2 columns check box in cgridViewtable and two bootstrap widgets TbButton in view page.
I can not get value of my checkbox very good. My value in checkboxs transfer into controller but changed id of checkboxs After a period of timeand , and controller don't knew checkbox,
View:
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
'id' => 'profile-information-form',
'enableAjaxValidation' => false,
));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'First validation'),));
$this->widget('bootstrap.widgets.TbButton', array('buttonType' => 'submit', 'type' => 'primary', 'label' => Yii::t('fa_ir', 'End validation'),));
$this->widget('zii.widgets.grid.CGridView', array(
'id' => 'profile-information-grid',
'dataProvider' => $model->children(),
'filter' => $model,
'columns' => array(
array(
'header' => '',
'value' => '$this->grid->dataProvider->pagination->offset + $row+1', // row is zero based
),
array(
'name' => 'ProfileInformation.user.scope',
'value' => 'CHtml::encode($data->user->scope->name)',
'filter' => Scope::model()->options,
),
array(
'name' => 'id',
'value' => 'CHtml::encode($data->id)',
),
array(
'name' => 'center',
'value' => 'CHtml::encode($data->center)',
),
array(
'name' => 'sendCount',
'value' => 'CHtml::encode($data->sendCount)',
'filter' => '',
),
// Use CCheckbox column with selectableRows = 2 for Select All
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser2(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
array('class' => 'CCheckBoxColumn', 'selectableRows' => 2, 'visible' => (Lookup::isUser1(Yii::app()->user->id) or Lookup::isAdmin(Yii::app()->user->id))),
),
));
// action button
$this->endWidget();
Controller:
if (isset($_POST['profile-information-grid_c10']) & isset($_POST['yt0'])) {
////Do action1
}
if (isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])) {
////Do action2
}
}
my problem is in $_POST['profile-information-grid_c10'] and _POST['profile-information-grid_c12'] , before id were $_POST['profile-information-grid_c8'] and $_POST['profile-information-grid_c10'] , and now is $_POST['profile-information-grid_c12'] and $_POST['profile-information-grid_c14'].
my problem is very involved. I cannot explain very good.
I want to have a fix id.
I donto why change id of check box?
Can I assign ids for checkboxs?
Can I assign ids for checkboxs? Sure, you better explicitly set checkbox column id:
'class' => 'CCheckBoxColumn', 'id'=>'column1', ... see these docs.
This way you firmly set it and you'll have no things like these yt0, yt2...
The same you can do for the buttons. See TButton docs.
Also you need to use double && in logical condition:
isset($_POST['profile-information-grid_c12']) & isset($_POST['yt1'])
I have a view helper that returns an array called $this->getTypes();
I've set it up as an invokable:
'view_helpers' => array(
'invokables' => array(
'getTypes' => 'Account\View\Helper\GetTypes',
),
),
If I echo it in the view can see the array, but in the form it fails.
I would like something like:
$this->add(array(
'name' => 'type_id',
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'required' => 'required',
),
'options' => array(
'label' => 'Type *',
'value_options' => $this->getTypes(),
),
));
Any ideas?
The short answer is: you don't
The medium answer is: to get DB-Values into your Zend\Form\Element\Select you have to inject your DB-/Service-Layer into your Form.
The long answer is: written in my Blog post Zend\Form\Element\Select and Database Values
I am trying to validate a multiply select using input filter, but every time I see a error. The error is "notInArray":"The input was not found in the haystack".(I use ajax but it doesn`t metter).
I will show part of my code to be more clear.
in Controller:
if ($request->isPost()) {
$post = $request->getPost();
$form = new \Settings\Form\AddUserForm($roles);//
$form->get('positions')
->setOptions(
array('value_options'=> $post['positions']));
//.... more code...
When I put print_r($post['positions']); I see:
array(0 => 118, 1 => 119)
in ..../form/UserForm.php I create the multiply element
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'attributes' => array(
'multiple' => 'multiple',
'id' => 'choosed_positions',
),
'required' => false,
'name' => 'positions',
));
and in the validation file the code is:
$inputFilter->add($factory->createInput(array(
'name' => 'positions',
'required' => false,
'validators' => array(
array(
'name' => 'InArray',
'options' => array(
'haystack' => array(118,119),
'messages' => array(
'notInArray' => 'Please select your position !'
),
),
),
),
What can be the reason every time to see this error, and how I can fix it?
By default selects have attached InArray validator in Zend Framework 2.
If you are adding new one - you will have two.
You should disable default one as follow:
$this->add(array(
'type' => 'Zend\Form\Element\Select',
'options' => array(
'disable_inarray_validator' => true, // <-- disable
),
'attributes' => array(
'multiple' => 'multiple',
'id' => 'choosed_positions',
),
'required' => false,
'name' => 'positions',
));
And you should get rid of the additional error message.
Please let us know if that would helped you.