HTML in YII2 Kartik Gridview column label (not heading) - yii2

I have a Kartik gridview in YII2 and I need to be able to put HTML into the label (not header, I'll come to that) of a column.
My column definition is as such
[
'attribute' => 'picked_percent',
'format' => 'raw',
'label' => 'P<span class="responsive">icked</span>',
],
But if I do this, it outputs
P<span class="drawn_head">icked </span>
I can change label to header and it looks fine but I need it to be clickable and it isn't when I change it to header.
I've also tried changing the format from raw to HTML and that makes no difference.
Any help is much appreciated.

If you want the label to not be encoded you need to add this config option in the column definition array:
'encodeLabel' => false

Related

yii2 formwizard checkbox field and customize preview step

I am using yii2-formwizard and I want to insert a checkbox as form input field for the field is_legal in a tabular step.
So in fieldConfig array, reading the documentation, I inserted the following code:
'is_legal' => [
'options' => [
'type' => 'checkbox',
],
'labelOptions' => [
'label' => \Yii::t('app', 'Legal Representative'),
],
],
The following image shows the result:
However, when I go the preview step I see the field of the checkbox set as undefined:
In fact, when I try to save the model, the is_legal field is not set.
First Question: where is the problem with the checkbox form field?
Second Question: is there any way to customize the preview step? For example instead of 'Step 5', I would like to write 'Legal Data'.
i created this widget and there are a few things you need to know.
First Answer
The undefined it is showing is not the value but the label of the checkbox, if you look into the getLabel() function in the formwizard.js file it looks into the siblings of the input field for a label and gets its text
let text = $('#' + fieldName).siblings('label').text();
to display on the preview step, and by default Yii2 wraps the input inside the label like
<label><input stype="checkbox"></label>
so you need to use the template option of the checkbox like below
'is_legal' => [
'options' => [
'type' => 'checkbox',
'template' => '{input}{beginLabel}{labelTitle}{endLabel}{error}{hint}',
],
'labelOptions' => [
'label' => \Yii::t('app', 'Legal Representative'),
],
],
Second Answer
No, currently the widget does not support the custom title for the Preview step sections, but i think I can add the support for providing the title of the headings as it makes sense too, if that sorts your problem.
Update
Ignore the Second Answer given above i just pushed the updates to the live branch you can now use the previewHeading option in the step settings. Update your composer by running composer update to update to the latest version and clear cache using CTRL+F5.
See the following sample code how to use previewHeading option
use buttflattery\formwizard\FormWizard;
echo FormWizard::widget([
'enablePreview'=>true,
'steps'=>[
[
'model'=>$user,
'title'=>'My Shoots',
'previewHeading'=>'My Heading Step 1',
'description'=>'Add your shoots',
'formInfoText'=>'Fill all fields'
],
[
'model'=> $profile,
'title'=>'My Shoots',
'previewHeading'=>'My Heading Step 2',
'description'=>'Add your shoots',
'formInfoText'=>'Fill all fields'
],
]
]);

kendo grid date column format after filtering

I have a kendo MVC grid that has a bound column like below
columns.Bound(c => c.CreatedDate).Format("{0:M/d/yyyy h:mm tt}").Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains"))).Format("{0: MM/dd/yyyy HH.mm.ss}");
the column formats fine when first loading the view:
06/22/2017 15.02.00
but i have some buttons which use AJAX to post back and get back filtered data and when re-populating the grid the column looks like this:
/Date(1498161720000)/
Any help?
First off, you have two seperate .Format tags with different formats specified, which is probably causing some problems. Pick which one you want to use and try just removing the other.
If that doesn't solve the problem, I would try declaring the format using data annotations. In your model, try adding this line above the declaration of CreatedDate:
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:M/d/yyyy h:mm tt}")]
and then remove .Format from your column binding.
i.e. change
columns.Bound(c => c.CreatedDate).Format("{0:M/d/yyyy h:mm tt}").Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
to
columns.Bound(c => c.CreatedDate).Title("Submitted on").Filterable(ftb => ftb.Cell(cell => cell.Operator("contains")));
and make sure you include the
using System.ComponentModel.DataAnnotations;
line at the top of your model if you don't already have it.

kartik Select2 FilterType in gridview doesn't work

I have an issue about kartik select2 filterType that doesn't work , this is a portion of my code :
[
'format' => ['link',$idmodel],
'attribute' =>$attribute,
'filterType'=>GridView::FILTER_SELECT2,
'filterWidgetOptions' => [
'data' => \yii\helpers\ArrayHelper::map($model_::find()->all(),$attribute,'nom_'.strtolower($idmodel)),
'options' => ['placeholder' => '-'.$idmodel.'-'],
'pluginOptions' => ['allowClear' => true],
'theme' => Select2::THEME_KRAJEE,
],
When i comment this line :
'filterType'=>GridView::FILTER_SELECT2,
a text field appear in my filter grid view.
Can any one help me ??
Thanks in advance
As I see it from your conversation with Edvin Tenovimas your problem is that no jQuery Javascript file is loaded. Did you installed the Select2 package normally with composer?
$ php composer.phar require kartik-v/yii2-widget-select2 "#dev"
In that case you have to see the file vendor/bower/jquery/dist/jquery.min.js. The file has to be copied into your assets directory under web/assets automatically. You could remove the content of the assets directories to force the creation of the assets again.
$ rm -rf web/assets/*
I believe by default GridView enables filtering unless you manually disable it. When you comment that out, it uses default text input instead of Select2. To also disable that one, use this on columns you want to disable filtering:
'filter' => false,

HTML in Yii2 GridView

I'm trying to display some HTML encoded strings as pure HTML in a column positioned in Yii2 GridView. The string that comes from the database looks like this:
Testing <span class='test'>HTML</span>
If I just display it using HTML decode Html::decode($theStringAbove); then I get this in the column:
Testing <span class='test'>HTML</span>
However, what I'm aiming at is simply getting Testing HTML and having the span tag around the HTML word in the code but not displayed as a string.
I've tried setting different values to the format attribute such as raw, url and html to no success. I also have no problem writing a custom function to return the correct output next to the value attribute, it's just that I can't figure out how to get to the output I need. Any suggestions are welcome, thank you!
EDIT: Here's a small code snippet if that's helpful:
[ 'format' => 'raw',
'value' => function($model) { return Html::decode($model->text); },
'label' => Yii::t('app', 'Some Label')]
The database output is probably encoded twice so instead of
Testing <span class='test'>HTML</span>
it's
Testing &lt;span class=&#039;test&#039;&gt;HTML&lt;/span&‌​gt;
Try to decode it twice like:
'value' => function ($model) {
return Html::decode(Html::decode($model->replace));
}

Raw HTML in HelperList column

I have a HelperList in Prestashop (1.6) with a few columns/rows. One of the columns is an anchor element (a href), and I need to show it like that in the list, but Prestashop escapes the value and represents it as a literal string.
How can I show an actual anchor element in one of the columns of a HelperList?
Plus: I'd like to not have to override PS classes nor copy the entire template just to change a single line of code. I do know how to do it using either of those ways, but I'm looking for something less "aggressive".
You can use this trick:
$fields_list = array(
'your_link' => array(
'title' => $this->l('Your title'),
'type' => 'bool',
'float' => true, // a trick - prevents from html escaping
// else code
),
);