x-editable

Bundle of widgets and server-side component for creating editable elements
49 followers

Overview

This extension allows you to create editable elements on your page.
It comes instead of previous yii-bootstrap-editable that was upgraded to X-editable library.
Major changes are:

  • support of several libraries: Twitter Bootstrap, jQuery UI and pure jQuery
  • popup and inline modes. You can toggle it from config without changing code
  • update of related models

It contains 4 widgets:

and 2 components:

Demo, Docs & Download

Please visit extension homepage: x-editable.demopage.ru

Requirements

Requirements depend on core library you want to use:

  • Bootstrap
    Twitter Bootstrap 2+, Yii 1.1+. You can use Yii-bootstrap extension (2.0+) or include bootstrap manually
  • jQuery UI
    • popup: Yii 1.1.13+ (as requires jQuery UI 1.9 for tooltip)
    • inline: Yii 1.1+
  • only jQuery
    Yii 1.1+

Support

If you have any questions or ideas feel free to ask in comments or open issue on github page.

Changelog

Version 1.2.0 May 29, 2013

[enh #7] column sort icons for bootstrap (vitalets)
[bug #41] if all columns have apply=false grid becomes un-editable after update (horizons2)
[enh #39] support php < 5.3 (vitalets)
[enh #37] added Editable::source method (vitalets)
[enh #38] CSRF support out of box (horizons2)
[enh #35] support of dates as timestamp (andersonamuller)
[enh] support of virtual_fields in EditableColumn (vitalets)

Version 1.1.0 May 18, 2013

[enh #33] allow apply as a PHP expression in EditableColumn (oinegue)
[enh #22] allow CArrayDataProvider for EditableColumn (ciarand)
[enh] added bootstrap datetime support (vitalets)
[enh #5] source as array is always data, not Yii route (vitalets)
[enh #9] support for namespaced models (vitalets)
[enh] updated to x-editable 1.4.4: added combodate and select2 (vitalets)
[enh #16] EditableDetailView defaults + french translation (mdeweerd)
[bug] If apply = true, attribute can be unsafe (vitalets)
[enh] Added composer support (vitalets)
[chg] EditableDetailView emptytext no more taken from nullDisplay option (vitalets)
[bug] Disable loading Yii's css for EditableDetailView in bootstrap mode (vitalets)
[enh #6] Added support of composite primary keys (vitalets)
[enh] Added Italian messages (vitalets)

Version 1.0.0 Dec 26, 2012

Initial release.

Total 20 comments

#13670 report it
cico at 2013/06/15 08:07am
Re: Using with mongoDB suite

Hi thank you for your fast reply i use this on my profile/view.php:

$this->widget('editable.EditableField', array(
        'type'      => 'text',
        'model'     => $model,
        'attribute' => 'profile.city',
        'url'       => $this->createUrl('user/updateUser'), 
        'placement' => 'right',
    ));

on my UsereController.php

public function actionProfile(){
$model = User::model()->findByPk( new MongoID(Yii::app()->user->id) );
$this->render('profile/view',array(
    'model'=>$model,
));
}

on my User.php

public function rules()
    {
        return array(
            array('email, status, profile.city', 'safe'),
        );
    }
 
    public function embeddedDocuments()
    {
        return array(
            // property field name => class name to use for this embedded document
            'profile' => 'Profile',
        );
    }

i set on my embedded document Profile.php

class Profile extends EMongoEmbeddedDocument
{
    public $lastname;
    public $firstname;
    public $street;
    public $city;
    public $zip;
    public $phone;
    public $cellular;
 
 
    /**
     * @return array validation rules for model attributes.
     */
    public function rules()
    {
        return array(
            //array('lastname, firstname, street, city, zip, phone, cellular', 'required'),
            array('lastname, firstname', 'length', 'max'=>50),
            array('phone, cellular', 'numerical', 'min'=>8, 'max'=>15, 'tooSmall'=>'Campo non valido inserisci un numero corretto', 'tooBig'=>'Campo non valido inserisci un numero corretto'),
            // The following rule is used by search().
            // Please remove those attributes that should not be searched.
            array('lastname, firstname, city, zip', 'safe'),
        );
    }

to use this modules i also edit your file EditableSaver.php here

//loading model
        $this->model = CActiveRecord::model($this->modelClass)->findByPk(new MongoId($this->primaryKey));
...

and here

//saving (no validation, only changed attributes)
        if ($this->model->update($this->changedAttributes, true)) {
...
#13668 report it
Vitalets at 2013/06/15 07:29am
Re: apply - depending on $data value

@Edgar Kuskov,
evaluating apply is seems to be already done.
have a look on:
https://github.com/vitalets/x-editable-yii/blob/master/EditableColumn.php#L95

For invalid date - could you show the full snippet?

@cico
could you show the code how you create widget for user.profile.name?

vitaliy

#13667 report it
cico at 2013/06/15 06:20am
Using with mongoDB suite

Hi, i'm try to use this great extension with mongoDBsuite and it work fine!

but i have a problem with embedded document in a "root" model, i can't edit the fields of embedded document. I try to explain with my real case:

My model is User.php and my embedded document is Profile.php. If I use edidableField widget and i try to edit a filed of embedded document for example $user->profile->name the field is not editabled.

I hope it is clear.

Thank you

#13642 report it
Edgar Kuskov at 2013/06/13 07:48am
apply - depending on $data value

Hello guys,

i would like to give a tip for the "apply" value in EditableClass, just change the line 65:

if($widget->apply)) { to if(!eval('return '.$widget->apply.';')) {

and now you are able to parse some really awesome conditions like: .... 'apply'=>'($data->manualPrice && strtotime($data->toDate)>strtotime(date("Y-m-d")))', ....

Thanks for the great extension!


P.S: There is a bug by date field, when i pass there a date like 2013-06-19 the field is always showing the todays date, i think there will be good to give the valueFormat.

#13453 report it
deez at 2013/05/29 10:55am
Filter and Sort

Works like a charm. Thanks again!

#13425 report it
Vitalets at 2013/05/28 05:22pm
Re: Filter and Sort?

@deez
please have a look on updated demo of 1.2.0, there is example of sorting by related model.

#13418 report it
deez at 2013/05/28 09:55am
Awesome

Thanks vitalets. Great extension by the way.

#13307 report it
Vitalets at 2013/05/21 06:34pm
Re: Filter and Sort?

hi deez,
your post bring me to some investigation of sources. I made several changes and will release 1.1.1 within a few days.

Thanks!

#13304 report it
deez at 2013/05/21 02:40pm
Filter and Sort?

Can anyone tell me how to filter and sort on a related model? For example:

array(
    'class' => 'editable.EditableColumn',
    'name' => 'relation.field_id',
    'header'=>'Field',
    'value'=> 'CHtml::value($data, "relation.field.somename")',
    'filter'=>CHtml::listData($this->getClientFields(), 'field_id','field.somename'),
    'editable' => array(
            'type'=>'select',
            'url' => $this->createUrl('updateEditable', array( 'model'=>'Model', 'field'=>'field_id')),
            'source' => CHtml::listData($this->getClientFields(), 'field_id', 'field.somename'),
            'placement'  => 'right',
            'inputclass' => 'span3',
     ),
),

In the compare statement in the Model I would normally create a pseudo element and call that in the grid, and the sort and the compare.

How do I do it with this method?

#13190 report it
Caio P. at 2013/05/13 03:32am
Replace value shown with server response

In case it helps anyone that needs to replace the user input with the actual saved value from the model.

In the controller:

/* after treatment of POSTed value into $model->value */
echo CJSON::encode(array('success' => true, 'newValue' => $model->value));

And in the view:

$this->widget('editable.EditableField', array(
    /* ... */
    'options' => array(
        'success'=>'js:function($response, $newValue) {
            var parsedResponse = JSON.parse($response);
            return { newValue: parsedResponse.newValue };
        }'
    ),
));
#12748 report it
Vitalets at 2013/04/09 02:14pm
re: Integrate in search form of grid view

hi,

For view please see samples.
For controller, if you are not updating model and just perform search, you just create action and use data from $_POST.

#12744 report it
zvik2004 at 2013/04/09 12:11pm
Integrate in search form of grid view

Hi, Great extension! I have a grid, and I have a search form for this grid. I would like to replace this search form with elements from this extension. Can you please have an example of what would be in the view and the controller? Thanks in advance! Zvi.

#12697 report it
clapas at 2013/04/06 05:45am
Re: Re: Bootstrap included manually

Thanks @haymps!

I included the bootstrap files manually, i.e. bootstrap.js, bootstrap.css and bootstrap-responsive.css.

I didn't add any extension nor did I change any configuration. I thought this implied that I added bootstrap manually.

Is it possible to make x-editable work under these conditions?

Cheers

#12688 report it
haymps at 2013/04/05 09:28am
Re:Bootstrap included manually

Have you downloaded bootstrap into your extensions folder?

Then add this in config/main.php

Yii::setPathOfAlias('editable', dirname(__FILE__).'/../extensions/x-editable');
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
...
// application components   
    'components'=>array(
    'bootstrap'=>array(
            'class'=>'bootstrap.components.Bootstrap',
        ),
        //X-editable config
        'editable' => array(
            'class'     => 'editable.EditableConfig',
            'form'      => 'bootstrap', 
            'mode'      => 'popup',      
            'defaults'  => array(        
             'emptytext' => 'Click to edit',

-all the best.

#12684 report it
clapas at 2013/04/05 04:28am
Bootstrap included manually

Hello,

I'm not using the Yii-bootstrap extension but included bootstrap manually. However, I get an exception when I try to use the EditableField widget reporting that no bootstrap component exists.

How can I use x-editable, having included the bootstrap files manually?

Thank you!

#12273 report it
le_top at 2013/03/10 11:09pm
Updates for EditableDetailView

Thanks for the extension. I was about to make a similar (lighter) one for DetailViews and I discovered this extension which already did pretty much what I needed.

I made some improvements so that it is easier to set default options for the 'EditableField' which is called by the 'EditableDetailView' (especially 'success') along with some other improvements/corrections.

All options of 'EditableField' are now available as options of 'EditableDetailView'. And I added the French translation.

I made a Pull Request with my changes.

#12119 report it
Daniel at 2013/02/27 07:53pm
X-editable 1.4.1

Hi Vitalets,

When I looked at the X-editable, it is already in version 1.4.1. While X-editable-yii v1.0 is still using X-editable 1.3.0. If, I just change the js and css files, Is it possible to do so? The feature that I really waiting for is Select2.

Could not wait for you to release new X-editable-yii.

Thanks,

Daniel

#12036 report it
Daniel at 2013/02/22 08:38am
EditableColumn of related model

Hi,

I have two models, Product and ProductPrice.

Product

id name unit

ProductPrice

id productFk FK to product(id) description minQty price

I have TBGridView of Product that also shows the Price for each product based on its min quantity of purchase. TBGridView is like this

| No | Name | Unit | Price Min Qty = 1| Price Min Qty = 3 | Price Min Qty = 6

Price Min Qty is defined on model ProductPrice while the TbGridView is using model Product (the $model is Product). I set editable for all Price Min Qty, how could I acomplish this task?

Cheers,

Daniel

#11955 report it
Vitalets at 2013/02/15 05:11am
Re: Variable types

yes, EditableColumn can only set single type for whole column.
But it's interesting, what is your final task?
maybe EditableDetailView would be suitable?

#11936 report it
haymps at 2013/02/13 03:40pm
Re: Re: Variable types - and new types 'text', 'select', 'date' etc.

I'm trying to do two things: Currently the type field applies to the entire column. The column is text or the column is data picker, etc. In thinking about it, I could pass in an array that has the type for each row of the column.

The other item is to add a color picker to one of the types. I will loog tat github link provided by Vitalets. Thanks!

Leave a comment

Please to leave your comment.

Create extension
Downloads
No downloadable files yet