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

displayValue initialization and value after update #6

Closed
arogachev opened this issue Aug 26, 2014 · 5 comments
Closed

displayValue initialization and value after update #6

arogachev opened this issue Aug 26, 2014 · 5 comments

Comments

@arogachev
Copy link

Let's say we have boolean value to edit (or integer values tied up with constants). Values in database are 0 for false and 1 for true.
To display user friendly values I wrote simple method which returns string 'yes' or 'no' according to attribute value. But when the value gets updated after ajax request, the new value becomes 0 or 1. That means it was directly taken from the JSON output and we must convert it to string by ourselves during JSON return.
I think it wiil be more flexible if we can just pass array like that [0 => 'No', 1 => 'Yes'] without creating dedicated method in model. For more complex arrays we can still use the method in model to retrieve array (or closure maybe). And if that array was set the value from the server after update will be automatically converted to proper string.
Or maybe it will be even better to have the separate options for array and single value and only one of them must be set.

@kartik-v
Copy link
Owner

Fixed with upgrade to new release 2.0. A new property displayValueConfig has been added. This can take in an array of 'value' and 'description'. Refer docs and demos.

@arogachev
Copy link
Author

Now after initializing widget with displayValueConfig correct string appears, but after updating value becomes raw integer. If displayValueConfig is set we need to transform value automatically after update too.
Also it will be useful to specify that displayValueConfig could be taken from data if we're using dropdown list. This helps to avoid duplicating code.
Or maybe it's redundant and it's enough to just write method in model and specify it in displayValue.

@kartik-v
Copy link
Owner

I think you still have a javascript caching problem - its referring old cached javascript or your extension is not updated properly - as mentioned in the other issue. You can check the demo page for the star rating refresh based on displayValueConfig.

@arogachev
Copy link
Author

Cleared the cache, but that doesn't solve the problem. Also tried to change output to empty string (as in demo example with star rating that you provided) - doesn't help too. After update the value becomes 0 or 1.

@kartik-v
Copy link
Owner

I am not sure I understand where you have the problem. Recheck your widget settings. On the demo page for example here is the setting for displayed value to automatically change via StarRating widget. On update - the rating returns a number 1 to 5 .. but the displayed value is auto calculated from displayValueConfig.

echo Editable::widget([
    'model'=>$model, 
    'attribute' => 'rating',
    'type'=>'success',
    'size'=>'lg',
    'displayValueConfig'=>[
        1=>'One Star',
        2=>'Two Stars',
        3=>'Three Stars',
        4=>'Four Stars',
        5=>'Five Stars',
    ],
    'inputType'=>Editable::INPUT_RATING,
    'editableValueOptions'=>['class'=>'text-success h2']
]);

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

No branches or pull requests

2 participants