2017 © Pedro Peláez
 

yii2-extension yii2-ajax-new

This widget allows you to easily create a new related entity from within a form in Yii, in a bootstrap Modal view.

image

inspire-agency/yii2-ajax-new

This widget allows you to easily create a new related entity from within a form in Yii, in a bootstrap Modal view.

  • Wednesday, February 11, 2015
  • by machour
  • Repository
  • 6 Watchers
  • 3 Stars
  • 31 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

yii2-ajax-new

This widget allow you to easily create a new related entity instance from within a form in Yii, in a bootstrap Modal view., (*1)

Let's suppose for instance that you have an Article model with a manyToOne relation with a Category model (article.category_id = category.id), (*2)

When creating a new Article, you realize that you didn't create the target Category yet. You would normally cancel the Article creation, create the Category, and then go back to the Article creation., (*3)

yii2-ajax-new will allow you to avoid that hassle by creating the new Category right away from the Article form., (*4)

A complete sample if provided below., (*5)

Installation

The preferred way to install this extension is through composer., (*6)

Either run, (*7)

php composer.phar require inspire-agency/yii2-ajax-new "*"

or add, (*8)

"inspire-agency/yii2-ajax-new": "*"

to the require section of your composer.json file., (*9)

Configuration

Assuming you have created both Article and Category models with the relation Article.category_id = Category.id, you will need to:, (*10)

  1. Configure your CategoryController as follows:
    public function actions()
    {
        return [
            'ajaxNew' => [
                'class'      => '\inspire\action\AjaxNewAction',
                'viewFile'   => '_form',
                'model'      => new Category(),
                'attr_id'    => 'id',
                'attr_label' => 'label',
            ]
        ];
    }
  1. Add the AjaxNew widget in your article/_form view:
$newCategory = AjaxNew::widget([
    'url' => Url::toRoute(['/category/ajaxNew']),
    'header' => '<strong>' . Yii::t('app', 'Create new category') . '</strong>',
    'selector' => '#article-category',
]);

// ...

<?= $form->field($model, 'category', [
'template' => "{label} " . $newCategory . " \n{input}\n{hint}\n{error}",

The Versions

11/02 2015

dev-master

9999999-dev https://github.com/inspire-agency/yii2-ajax-new

This widget allows you to easily create a new related entity from within a form in Yii, in a bootstrap Modal view.

  Sources   Download

BSD-3-Clause

The Requires

 

by Selim Achour

extension form yii widget modal