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

displayValueConfig not working after Ajax change of Value #24

Closed
mtangoo opened this issue Nov 24, 2014 · 6 comments
Closed

displayValueConfig not working after Ajax change of Value #24

mtangoo opened this issue Nov 24, 2014 · 6 comments
Labels

Comments

@mtangoo
Copy link

mtangoo commented Nov 24, 2014

           'attribute'=>'contact_email',
            'format'=>'raw',

            'value'=>Editable::widget([
                'model'=>$model, 
                'attribute' => 'contact_email',
                'type'=>'primary',
                'format' => Editable::FORMAT_BUTTON,
                'inputType' => Editable::INPUT_DROPDOWN_LIST,
                'data'=>[1=>'Allow', 0=>'Forbid'],
                'displayValueConfig'=>[0=>Yii::t('app','Forbidden'), 1=>Yii::t('app','Allowed')],
                'editableValueOptions'=>['class'=>'text-success pad15-right'],
                'formOptions'=>[
                    'action'=>url::to(['member/usercp', 'id'=>$model->id])
                ],
                'pluginEvents' => [
                    "editableSuccess"=>"function(event, val) { 
                        //console.log('Successful submission of value ' + val); 
                    }",
                ],

That is relevant part of widget and It works fine. But after ajax change it shows 0/1 instead of allowed/forbidden. Is that normal? IMHO it should apply formula to that thing. Or at least expose the display container in pluginEven something like below so that one can simly do what he wants

                 'pluginEvents' => [
                    "editableSuccess"=>"function(event, val, displayer) { 
                        $(displayer).val(val);
                    }",
@kartik-v
Copy link
Owner

Yes its supposed to automatically generate the displayed value based on displayValueConfig. You need to debug and check.

In addition, for complex use cases you can also send it with the Json output from your controller which will be displayed. The json response is

// if output is empty (which is the default) the extension will use the input element value to display
$out = Json::encode(['output'=>'', 'message'=>'']);

// if output is set to a value then extension will display this instead of the input element value
$out = Json::encode(['output'=>'forbidden', 'message'=>'']);

@mtangoo
Copy link
Author

mtangoo commented Nov 24, 2014

I will go with second option. Thanks!

@mtangoo mtangoo closed this as completed Nov 24, 2014
@mtangoo
Copy link
Author

mtangoo commented Nov 24, 2014

I forgot that I use the same Action for all model attributes. So the second one is not going to work.
Where should I check? Where is JS that does the thing resides? I believe something is wrong there!

@mtangoo mtangoo reopened this Nov 24, 2014
@newerton
Copy link

The problem is "Json::encode()" in 'InputWidget'. The 'Json::encode()' creates the array 'displayValueConfig', eliminating the 'key' if they are numeric.

To work, it would be good to put the number 80 in 'Json::encode()'.

$this->_encOptions = empty($this->pluginOptions) ? '' : Json::encode($this->pluginOptions, 80);

Before you make the change javascript looks like this:

var editable_950d7e48 = {"defaultValue":"<em>(not set)</em>","placement":"left","target":".kv-editable-link","displayValueConfig":["Forbidden","Allowed"],"showAjaxErrors":true};

After the change

var editable_950d7e48 = {"defaultValue":"<em>(not set)</em>","placement":"left","target":".kv-editable-link","displayValueConfig":{"0":"Forbidden","1":"Allowed"},"showAjaxErrors":true};

@kartik-v
Copy link
Owner

You do not require to change Json encode for this. I have provided a fix.

@newerton
Copy link

@kartik-v tranks!

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