2amigos / yii2-editable-widget

X-Editable Widget for Yii2
Other
58 stars 20 forks source link

Assigning function to url param. #11

Closed alagodich closed 9 years ago

alagodich commented 9 years ago

Hello

I am trying to assign function to editable url property, as it is being stated here: https://github.com/2amigos/yii2-editable-widget/blob/master/Editable.php#L43

But when it comes to https://github.com/2amigos/yii2-editable-widget/blob/master/Editable.php#L174 It always creates path without checking if there is a function, not url.

It happens here: https://github.com/yiisoft/yii2/blob/master/framework/helpers/BaseUrl.php#L134 It just concatenates everything we passed there with the current route.

For example, if i set in the search controller:

"url" => "function(params) {}"

I will get:

"url":"/search/function(params) {}"
alagodich commented 9 years ago

Maybe i am wrong, but we could probably check if the value in url param is JsExpression? and pass it like:

'url' => new JsExpression($script)

Because if we for example pass an instance of JsExpression to the display param, it will render as expected.

Something like this would do i think.

        if ($this->url instanceof JsExpression) {
            $this->clientOptions['url'] = $this->url;
        } else {
            $this->clientOptions['url'] = Url::toRoute($this->url);
        }
tonydspaniard commented 9 years ago

You are right @alagodich I'll try to tackle it asap but I am quite busy atm