laravel backpack select2 placeholder - dropdown

How do I get dropdown list with placeholder saying "Select Category" as the default selection?
The following code did not render the placeholder
$this->crud->addField([ // Select2
'label' => 'Category',
'type' => 'select2',
'name' => 'category_id', // the db column for the foreign key
'entity' => 'category',
'attribute' => 'name',
'attributes' => ['placeholder' => 'Select a category'],
.... ])

add this in attributes:
'attributes' => [
'data-placeholder' => 'Select Category'
]

Try just the
'placeholder' => 'Select Category',
without the 'attributes' => [...], that worked for me.

Related

Add color to carrier column to order table in Prestashop administrative office

Add the carriers column, and to the table 'ps_carrier_lang' add a column named 'color' as in the statuses, I want that color to be displayed.
'carrierdelay' => array(
'title' => $this->l('Envio'),
'type' => 'text',
'align' => 'text-center',
'class' => 'fixed-width-xl',
'color' => 'color',
'filter_key' => 'carrier_lang!delay',
'filter_type' => 'text',
'order_key' => 'carrier_lang!delay'
),
if I put 'color' => 'color',it will bring me the same color of the order status, but I want to define another type of color to the carriers
Add a callback:
...
'carrierdelay' => array(
'title' => $this->l('Envio'),
'type' => 'text',
'align' => 'text-center',
'class' => 'fixed-width-xl',
'color' => 'color',
'filter_key' => 'carrier_lang!delay',
'filter_type' => 'text',
'order_key' => 'carrier_lang!delay'
'callback' => 'colorCarrier'
),
...
function colorCarrier($value, $object) {
if ($object['carrierdelay'] > 3) { // Do the compare that you need, and set desired colors
$backgroundColor = '#4169E1';
$color = 'white';
}
// Return span with color and string
return '<span class="label color_field" style="background-color:'.$backgroundColor.';color:'.$white.'">'.$this->l("Delayed").'</span>';
}

hook with form Prestashop 1.7

guys (and ladies)
I like to ask you how to build the forms (formbuilder) in Prestashop 1.7 for the current 2020 year.
I created module with classes and hooks, but I can't find the info on how to create forms via "classes" and "controllers".
I'd happy to have something like this:
What have already done:
created custom module
created custom hook
custom .tpl from /module/templates/front/custom.tpl is added to the hook and displays data correctly.
Using form builder in your .php file (or controller)
return array(
'form' => array(
'legend' => array(
'title' => $this->l('Settings'),
'icon' => 'icon-cogs',
),
'input' => array(
array(
'type' => 'switch',
'label' => $this->l('Live mode'),
'name' => 'TESTONE_LIVE_MODE',
'is_bool' => true,
'desc' => $this->l('Use this module in live mode'),
'values' => array(
array(
'id' => 'active_on',
'value' => true,
'label' => $this->l('Enabled')
),
array(
'id' => 'active_off',
'value' => false,
'label' => $this->l('Disabled')
)
),
),
array(
'col' => 3,
'type' => 'text',
'prefix' => '<i class="icon icon-envelope"></i>',
'desc' => $this->l('Enter a valid email address'),
'name' => 'TESTONE_ACCOUNT_EMAIL',
'label' => $this->l('Email'),
),
array(
'type' => 'password',
'name' => 'TESTONE_ACCOUNT_PASSWORD',
'label' => $this->l('Password'),
),
),
'submit' => array(
'title' => $this->l('Save'),
),
),
);
}

Yii ESelect2 extension show preselected valued

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',
),
));

bootstrap.widgets.TbDetailView, Yii app

Model--
enter code here
public function searchShop()
{
$criteria = new CDbCriteria();
$criteria->compare("name", $this->category, TRUE, "OR");
$criteria->compare("shopname", $this->category, TRUE, "OR");
$criteria->compare("category", $this->category, TRUE, "OR");
return Shops::model()->findAll($criteria);
}
code----
enter code here
<?php
foreach($models as $model):
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
'ID' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('name' => 'ID', 'label' => 'ID'),
),
)
);
echo "<br><hr><br>";
endforeach;
?>
I want a link on ID by clicking on it it will render view file i.e view.php of shops model
I used CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID)) but it is showing path of that view as 1
help me...
thanks in advance
try
CHtml::link(CHtml::encode($model->ID),
CController::createUrl('site/view',array('id'=>$model->ID)))
here i have assumed that action view lies in site controller. If it lies under some other module name then you can write like this "moduleName/controllerName/actionName"
Edit:
Ok you have to try a few things. TbDetailView extends CDetatilView. Now you can use TbDetailView as
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' => array(
'id' =>array('view', 'id'=>$model->ID),
'Shop Name' => $model->shopname,
'Category' => $model->category,
),
'attributes' => array(
array('name' => 'Shop Name', 'label' => 'Shop name'),
array('name' => 'Category', 'label' => 'Category'),
array('label' => 'ID', 'value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))),
),
)
);
You can also do like
$this->widget(
'bootstrap.widgets.TbDetailView',
array(
'type'=>'bordered condensed',
'data' =>$model,
'attributes' => array(
array('name' => 'shopname', 'label' => 'Shop name'),
array('name' => 'category', 'label' => 'Category'),
array('value' => CHtml::link(CHtml::encode($model->ID), array('view', 'id'=>$model->ID))
),, 'label' => 'ID'),
),
)
)
;

Prestashop upload field image display

I created new AdminReferenceController in prestashop back office with list and form for every item in list, and everything is working fine except one thing. When i try show image below upload button image is not displayed, (i check, image exist on server and url is valid). I use prestashop 1.5.6.0 Please check what i am doing wrong? Name and description values is properly displayed...
public function renderForm()
{
$this->fields_form = array(
'tinymce' => true,
'legend' => array(
'title' => $this->l('Reference'),
'image' => '../modules/reference/logo.gif'
),
'input' => array(
array(
'type' => 'text',
'lang' => false,
'label' => $this->l('Reference name:'),
'name' => 'name',
'size' => 60,
'desc' => $this->l('Reference name')
),
array(
'type' => 'file',
'lang' => false,
'label' => $this->l('Reference image:'),
'name' => 'image',
'display_image' => true,
'desc' => $this->l('Upload Reference image from your computer')
),
array(
'type' => 'textarea',
'label' => $this->l('Reference description:'),
'name' => 'description',
'autoload_rte' => true,
'desc' => $this->l('Reference description')
)
),
'submit' => array(
'title' => $this->l('Save'),
'class' => 'button'
)
);
if (!($obj = $this->loadObject(true)))
return;
$this->fields_value = array(
'image' => "<img src='/prestashop/img/reference/1.jpg'>",
'size' => '500',
'name' => 'test',
'description' => 'test'
);
return parent::renderForm();
}
Thanks
You can also use this code if it helps you
public function renderForm()
{
if (!($obj = $this->loadObject(true)))
return;
$image = _PS_MANU_IMG_DIR_.$obj->id.'.jpg';
$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$obj->id.'.'.$this->imageType, 350,
$this->imageType, true, true);
$image_size = file_exists($image) ? filesize($image) / 1000 : false;
$this->fields_form = array(
'legend' => array(
'title' => $this->l('Add Maker'),
'icon' => 'icon-maker'
),
'input' => array(
array(
'type' => 'text',
'label' => $this->l('Name'),
'name' => 'name',
'required' => true
),
array(
'type' => 'file',
'label' => $this->l('Maker Image'),
'name' => 'image_url_maker',
'image' => $image_url ? $image_url : false,
'size' => $image_size,
'display_image' => true,
'col' => 6,
'hint' => $this->l('Upload a maker image from your computer.')
),
),
'submit' => array(
'title' => $this->l('Save'),
)
);
return parent::renderForm();
}