X-Editable In Detailview?

Hello,

Does anyone know how (or if possible) to put the xeditable into the detail view?

or

Regards,

Dennis

You would need to return the widget markup in the attribute value.




// set this in your detail view attributes

[

   'attribute' => 'attrib_name',

   'format' => 'raw',

   'value' => TheEditableWidget::widget([

        'model'=>$model,

        'attribute'=>'attrib_name', 

        // other options

    ]),

]



Alternatively, you could also try my yii2-detail-view extension - it allows you to completely toggle VIEW and EDIT modes in DetailView. You can check a demo here.

Kartik,

your detail view looks great i have seen previously and will use int he future. I was trying to follow some consistency on a current page and also wanted to get this working. I only succeed in getting the html code back in the detail view which i assume is produced by the widget.

i have tried with ‘type’=> ‘raw’ which i assume is the old way in yii1 and now have tried with ‘name’=>‘name:raw’, but still no luck. Still shows in html markup.

ideas?


                    [

                        'name'=>'name:raw',

                        //'type'=>'raw',

                        // 'attribute' => 'name',

                        'label'=>'Intro',

                        'value' => \mcms\xeditable\XEditableTextArea::widget([

                            'model' => $model,

                            'placement' => 'right',

                            'pluginOptions' => [

                                'name' => 'name',

                            ],

                            'callbacks' => [

                                'validate' => new \yii\web\JsExpression('

                                    function(value) {

                                        if($.trim(value) == "") {

                                            return "This field is required";

                                        }

                                    }

                                ')

                            ]

                        ]),

                    ]

Ready X-Editable options, and use events to call html value, text, etc with jquery, javascript, ok.

echo \mcms\xeditable\XEditableTextArea::widget([

				'id' => 'content',


				'model' => $model,


				'pluginOptions' => [


					'url' => '/content/editable',


					'name' => 'content',


				],


				'events' => [


					'display' => new \yii\web\JsExpression('


						function(value) {


						  $(this).html(value);


						}


					')


				],


			]);

The array keys/params you used for setting up detail view attributes are wrong (its a bit different in Yii2 than Yii1)… you may want to check the yii\widgets\DetailView guide.

You must use something like the following:




[

   'attribute'=>'name',

   'format'=>'raw',

   'label'=>'Intro',

   'value' => $yourEditableWidget

]



Wahoo, we have a winner. That worked. Thanks.