Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TbHighCharts, problem with encode options #696

Closed
TheHett opened this issue Oct 9, 2013 · 6 comments
Closed

TbHighCharts, problem with encode options #696

TheHett opened this issue Oct 9, 2013 · 6 comments
Labels
Milestone

Comments

@TheHett
Copy link

TheHett commented Oct 9, 2013

Hi, after this fix dc41267

I now understand, how to translate js code to options?

before it was done so

            $this->widget('TbHighCharts', array(
                'options' => array(
                    'tooltip' => array(
                        'formatter' => "js:function() {
                                        return Highcharts.numberFormat(this.y, 0) + ' by ' + this.series.name +'<br/>'+' in '+ this.x;
                                       }",
                    ),
                ),
            ));

now its not work :'(

@hijarian
Copy link
Contributor

hijarian commented Oct 9, 2013

Haha, absolutely hilarious. What regressions can appear after seemingly innocent fixes.

Thanks for pointing out this problem, @TheHett obviously options cannot be processed as a JSON because JSON doesn't have a way to store functions. This fix is wrong.

I was going to review TbHighCharts anyway. Maybe someone can give you different answer, but I suppose your only option for now is to use a custom fork in which to revert that commit. Sorry about that, I'll fix this behavior soon.

@TheHett
Copy link
Author

TheHett commented Oct 10, 2013

ok, we while using old version =)
I not have idea solutions to both problems :-\

@Krinopotam
Copy link

The same problem in TbRedactorJs and in any other widget that uses Bootstrap->registerPlugin(...)

    $options = empty($options)
        ? ''
        : json_encode($options);

So, we can pass no callback function to RedactorJs for example.

@hijarian
Copy link
Contributor

OK, thanks for pointing it out, @Krinopotam. Hopefully I will be able to do something with it on this weekend.

@hijarian
Copy link
Contributor

For HighCharts I replaced the CJavaScript::jsonEncode with CJavaScript::encode. I don't know now how to reproduce the issue explained in #345 (the one with zero values in HighCharts).

Anyway, the only proper way to incorporate function definitions inside the HighCharts options is to use the CJavaScriptExpression class.

See the examples at documentation website.

@hijarian
Copy link
Contributor

RedactorJs got the same changes, with same effect. Use CJavaScriptExpression to pass javascript functions to the widget options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants