Help with Html helpers

This seems pretty simple to me, but I can’t see to get it to work. I’ve did some googling and what I found says this should work, but it does not. I am new, so maybe something has changed, but I didn’t find any documentation to prove something changed

I want to add a onClick attribute to a Html::a() helper, but the rendered HTML doesn’t have an onClick attribute

Html::a(FAS::icon('trash'), ['user/delete/' . Html::encode($data->id)], ['onClick' => 'something']);

@jasin;

Gretings, if read the method a on \yii\helpers\BaseHtml

can read this parameters

public static function a($text, $url = null, $options = [])

That’s not helpful. I’m already supplying an array to options that has a key => value pair.

the only thing I read there that suggest why it’s not being rendered is because the value is null, which it isn’t. What am I missing??

Edit: and if I add in another key => value pair like ‘class’ => ‘mx-auto’ that is rendered fine. but yet there is no onClick attribute rendered.

Check those images…

i setted parameters requested on method mentioned

Check console attribute onClick setted on element “a”

I’m happy to accept that it works for you and everyone else. But that is not why I am here.

As new user I am limited to one picture per post

Hi Jasin,

it’s because you format the output as ‘html’.
So the formatter of the GridView (default is the Yii formatter) processes it and uses the HtmlPurifier to strip evil code away.
Change the format type to ‘raw’ and you can use your attribute.

1 Like

Thank you, I was just finishing a xdebug session and noticed the HTML purifier was stripping the attribute. Now I understand why