Prestashop 1.7.4.1
I want to add two new fields only for features but that seems more complex, I already try this Prestashop custom field but it doesn't work for my version even following PS documentation for overwriting.
My main goal is to have a title, icon and description that allows HTML inside product features.
But that seems way too much for a simple task, so instead I'd like to know how I can enable the WYSIWYG textarea, I have manages to change the input from type text to textarea:
array(
'type' => 'textarea',
'label' => $this->trans('Value', array(), 'Admin.Global'),
'name' => 'value',
'lang' => true,
'size' => 255,
'hint' => $this->trans('Invalid characters:', array(), 'Admin.Notifications.Info').' <>;=#{}',
'required' => true
),
So, the question is, how to enable HTML editor in product features.
I'm new in PrestaShop, I have read in forums but no help I can find regarding this implementation.
Thank you in advance.
UPDATE 10-10-2018 6:56 (GTM-5)
I Fix the HTML part, now is the matter of validation, it still blocking all html tags...
Add this to your field array: 'autoload_rte' => true that way you can activate the TinyMce editor for Features input value, If I'm not mistaken that is on function: initFormFeatureValue(), on that same function look for Tools::safeOutput(Tools::getValue('back', '')); and add true before ); check if that works.
UPDATE
Open FeaturesValue.php in folder classes, look in line 53
'value' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255),`
Replace it with:
'value' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml', 'required' => true, 'size' => 255),
Then in your TPL product-details.tpl look for:
{block name='product_features'}
{if $product.grouped_features}
<section class="product-features">
<p class="h6">{l s='Data sheet' d='Shop.Theme.Catalog'}</p>
<dl class="data-sheet">
{foreach from=$product.grouped_features item=feature}
<dt class="name">{$feature.name}</dt>
<dd class="value">{$feature.value|escape:'htmlall'|nl2br nofilter}</dd>
{/foreach}
</dl>
</section>
{/if}
{/block}
Replace it with:
{block name='product_features'}
{if $product.grouped_features}
<section class="product-features">
<p class="h6">{l s='Data sheet' d='Shop.Theme.Catalog'}</p>
<dl class="data-sheet">
{foreach from=$product.grouped_features item=feature}
<dt class="name">{$feature.name}</dt>
<dd class="value">{$feature.value nofilter}</dd>
{/foreach}
</dl>
</section>
{/if}
{/block}
In this block you only need to change {$feature.value|escape:'htmlall'|nl2br nofilter} for {$feature.value nofilter} and that is it...
I hope it works, keep in mind that while in product edit/new when adding a new feature you can only select from what you have, what I mean is that if you want a custom value while editing a product the input for feature custom value will still in type text, but I hope that with this you have a better idea on how to change the rest.
PrestaShop use HTML escape on tpl files:
<td>{$feature.name|escape:'html':'UTF-8'}</td>
<td>{$feature.value|escape:'html':'UTF-8'}</td>
you have to change it to display HTML (on your theme):
<td>{$feature.name}</td>
<td>{$feature.value}</td>
Related
I want to apply validation rules only for the input fields that are not empty (not required) for the URL
For example,
If I submit a form and the input is empty, I got a validation error "Instagram Link must be valid URL.", However, I want it without requiring,
and if the input is not empty, I want to apply the rule "valid_url"
How can we fix it?
if (!$this->validate([
'instagram' => [
'rules' => 'valid_url',
'errors' => [
'valid_url' => 'Instagram Link must be valid url.',
],
],
])){
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
I tried with a permit_link rule, but if I submit it (with an input value like 'mylink' (which is not a valid_url)), it will accept it, but it should not.
Please check the following images and the code:
A form HTML
Result after clicking on edit button
<?= form_open('/settings/edit/1', ['id' => 'setting-form']); ?>
<div class="row">
<div class="col-md-6">
<div class="form-group">
<?= form_label('Instagram'); ?>
<?= form_input(['name' => 'instagram', 'class' => 'form-control', 'id' => 'instagram', 'placeholder' => 'Enter instagram link', 'value' => old('instagram', $setting->instagram)]); ?>
</div>
</div>
</div>
<button type="submit" class="btn btn-dark">Edit</button>
<?= form_close(); ?>
public function edit($id)
{
if (!$this->validate([
'instagram' => [
'rules' => 'permit_empty|valid_url',
'errors' => [
'valid_url' => 'Instagram Link must be valid url.',
],
],
])) {
return redirect()->back()->withInput()->with('errors', $this->validator->getErrors());
}
die('submitted');
}
It should display "Instagram Link must be valid url" and not "submitted",
first
Use separate variable $rules like this :
$rules = ['data' => 'require']
Then
check if $this->request->getVar("instagram"); is empty / is true or etc.. then set it on the $rules
finally
Do Something like this :
$rules = ['extra_data' => 'require'];
if(!empty($this->request->getVar("instagram"))
$rules["instagram"] = "valid_url";
if ($this->validate(rules){
//do something ...
}else {
//do something ...
}
I just noticed that the following examples:
"mylink", "mylink.com", "https://www.mylink.com"
will consider correct for the rule valid_url in Codeigniter (No errors),
While: "https:://www.mylink.com", "mylink#" will apply the validation and the error is applied.
I am using Laravel Collective form. I want to use onclick analytic.js but the browser shows me an error. here is the code
<div class="field-name">
{{--<%= f.text_field :name, placeholder: 'your name', :onclick => "ga('send','event', 'form-lp-input', 'step3-name', '', 0);" %>--}}
{!!Form::text('name','yes',null,['placeholder'=>'yourname','onclick'=>'ga('send', 'event', 'form-lp-input', 'step2-zip',
'', 0);'])!!}
</div>
here is the output
There are two problems in your code:
Form::text() only uses 3 parameters, you are passing 4:
public static function text($name, $value = null, $options = array())
You have to escape your single-quoted javscript string or use double-quotes:
try this:
{!!Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => 'ga("send", "event", "form-lp-input", "step2-zip","", 0);'])!!}
I see I'm answering a bit late :) but still, maybe this solution will help someone...
To escape quotes you can use \Illuminate\Support\HtmlString class as following:
{!! Form::text('name', 'yes', ['placeholder' => 'yourname', 'onclick' => (new \Illuminate\Support\HtmlString("ga('send', 'event', 'form-lp-input', 'step2-zip', '', 0)"))]) !!}
As example, i have code:
$builder->add('fieldname', null, array(
'constraints' => array(
new NotBlank(),
new Length(array('min' => 3, 'max' => 255)),
),
));
How i can select field as red or add him some css class when validation is false?
Use TWIG to add custom CSS class if the field is not validated. Here is how :
TWIG:
<div class="{{ fieldname.vars.errors|length > 0 ? 'field-has-error-class' : '' }}">
{{form.fieldname}}
</div>
This will add your custom-CSS error without the need of handling it with code.
hope this helps.
I'm just learning Yii a few days ago to developer a website for company. Now i have some issue with Yii pagination and i really need your help.
Currently i can make Yii pagination. However, i need to create a button besides pagination area. Everytime, i click that button, it will call ajax to load next page or previous pages (if current page is last page).
Here is my model:
public function getListDesc()
{
$arrPlace = array(0 => '--- --- --- ---');
$criteria=new CDbCriteria;
$criteria->select='t.*,pi.path path';
$criteria->join='JOIN places_images pi ON t.id=pi.places_id';
$criteria->group = 't.id';
$criteria->compare('t.deleted', '<>1', false);
$criteria->compare('t.status',1);
$criteria->compare('outlet','Outlet 1');
$criteria->order = 't.id DESC';
return new CActiveDataProvider('Places', array(
'criteria'=>$criteria,
'pagination' => array(
'pageSize' => 2
)
));
}
Here is a part of my index page which is call that model:
<?php
$this->widget('zii.widgets.CListView', array(
'id' => 'places-list-right',
'dataProvider'=> Places::model()->getListAsc(),
'summaryText'=>'',
'pager' => array(
'header' => '',
'prevPageLabel' => '<<',
'nextPageLabel' => '>>',
),
'itemView'=>'_fea_oulet',)
);
?>
Here is _fea_oulet.php file:
<div class="place_img" id="<?=$data->id?>">
<div class="plusimage">
<a href="javascript:void(0);" onclick="randnew();">
<img alt="<?=$data->id?>" src="<?php echo Yii::app()->request->baseUrl; ?>/images/9life-show-more-images.png" style="border:none;border-radius:0;-webkit-border-radius: 0; -moz-border-radius:0">
</a>
</div>
<?php echo CHtml::image("timthumb.php?src=".$data->path."&w=294&h=294&zc=1&q=100",$data->title);?>
<div class="featitle">
<h3><span><?php
if(strlen($data->title) > 30) {
echo CHtml::encode(mb_substr($data->title,0,30,'UTF-8')) . '...';
}
else{
echo CHtml::encode($data->title);
}
?></span>
<img src="<?php echo Yii::app()->request->baseUrl; ?>/images/9life-show-more-green.png" style="border:none;border-radius:0;-webkit-border-radius: 0; -moz-border-radius:0">
</h3>
</div>
</div>
Any help are appreciates.
Thanks,
You can override CLinkPager class and use your own implementation MyLinkPager in your CListView widget's call specifying its pager property like this:
$this->widget('zii.widgets.CListView', array(
'id' => 'places-list-right',
'dataProvider' => Places::model()->getListAsc(),
'summaryText' => '',
'pager' => array(
'class' => 'MyLinkPager',
'header' => '',
'prevPageLabel' => '<<',
'nextPageLabel' => '>>',
),
'itemView' => '_fea_oulet'
));
run() method of CLinkPager is the place where pager buttons' rendering happens so you can override this method directly. Or you can override createPageButtons() method by adding your custom button to $buttons array if you want to see it along with other page buttons.
in my project i am using the cgridview inside a modal window. now i am facing the problem that when i select the pagination the page get reloaded. how can i load the grid view with ajax pagination. my ui code id given below...
<div id="pick-category-modal" title="Pick Category" class="popupinfoholder2">
<div style="width:700px; height:auto;">
<?php
$widget = $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'response-grid',
'dataProvider' => $pickdataset->pickSection(),
'cssFile' => Yii::app()->baseUrl . '/media/css/gridview.css',
'summaryText' => '',
'ajaxUpdate'=>true,
'enablePagination' => true,
'template' => '{items}',
'pager' => array(
'class' => 'LinkPager',
'cssFile' => false,
'header' => false,
'firstPageLabel' => 'First',
'prevPageLabel' => 'Previous',
'nextPageLabel' => 'Next',
'lastPageLabel' => 'Last',
),
'columns' => array(
.....................
.....................
),));
?>
<div class="grid-view-footer">
<div class="paginationholder">
<div id="pagination">
<?php $widget->renderPager(); ?>
</div>
</div>
</div>
</div>
</div>
Just testing this myself a moment ago, it appears that the pager kicked out with renderPager() does not work with the AJAX setting. The CGridView JavaScript only binds the AJAX to pagers inside the <div> rendered by the widget (#response-grid here), so it does not find and use your additional pager.
I just use the default pager that the CGridView renders at the bottom, and that works fine.
You could override the CGridView JS to fix this, or list it as an enhancement on the Yii bug tracker: http://code.google.com/p/yii/issues/list