Coder Social home page Coder Social logo

yii2-editors's Introduction

Krajee Logo
yii2-editors
Donate

Stable Version Unstable Version License Total Downloads Monthly Downloads Daily Downloads

Editor widgets for Yii2 framework - Summernote and Codemirror.

Summernote is a WYSIWYG rich text HTML input widget which uses the Summernote WYSWIYG plugin and is styled for both Bootstrap 3.x & 4.x. Includes additional enhancements by Krajee for Bootstrap 3.x and 4.x support, and ability to format code, and render preset configurable toolbars.

Codemirror is a plain text code editor that allows syntax formatting of various code.

Installation

The preferred way to install this extension is through composer. Check the composer.json for this extension's requirements and dependencies. Read this web tip /wiki on setting the minimum-stability settings for your application's composer.json.

To install, either run

$ php composer.phar require kartik-v/yii2-editors "@dev"

or add

"kartik-v/yii2-editors": "@dev"

to the require section of your composer.json file.

Refer the CHANGE LOG for details of release wise changes.

Demo

You can see detailed documentation and examples on usage of the extension.

Prerequisites

The Codemirror widget requires Font Awesome Icon assets rendered on the page for rendering the toolbar. You can render the font awesome icon assets on your page using one of the options below:

  • Option 1: Font CSS version of Font Awesome:
<!-- on your view layout file HEAD section -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">
  • Option 2: SVG / JS version of Font Awesome (e.g. from kartik-v/yii2-icons library):
// on your view layout file
use kartik\icons\FontAwesomeAsset;
FontAwesomeAsset::register($this);

Usage

Summernote WYSIWYG Editor

Summernote Editor Screenshot

use kartik\editors\Summernote;

// Usage with ActiveForm and model and default settings
echo $form->field($model, 'content')->widget(Summernote::class, [
    'options' => ['placeholder' => 'Edit your blog content here...']
]);

// With model & without ActiveForm and default settings
echo Summernote::widget([
    'model' => $model,
    'attribute' => 'html_content',
]);

// Without model and setting advanced custom widget configuration options
echo Summernote::widget([
    'name' => 'blog_post',
    'value' => '',
    'useKrajeeStyle' => true,
    'useKrajeePresets' => true,
    'enableFullScreen' => true,
    'enableCodeView' => false,
    'enableHelp' => false,
    'enableHintEmojis' => true,
    'hintMentions' => ['jayden', 'sam', 'alvin', 'david']
]);

Codemirror Code Editor

Codemirror Editor Screenshot

use kartik\editors\Codemirror;

// Usage with ActiveForm and model and default settings
echo $form->field($model, 'program_code')->widget(Codemirror::class, [
    'preset' => Codemirror::PRESET_PHP,
    'options' => ['placeholder' => 'Edit your code here...']
]);

// With model & without ActiveForm and default settings
echo Codemirror::widget([
    'model' => $model,
    'attribute' => 'json_code',
    'preset' => Codemirror::PRESET_JSON,
]);

// Without model and setting advanced custom widget configuration options
echo Codemirror::widget([
    'name' => 'js_code',
    'value' => '',
    'preset' => Codemirror::PRESET_JS,
    'useKrajeePresets' => true,
    'libraries' => [
        'addon/display/placeholder.js',
        'addon/fold/xml-fold.js',
        'addon/edit/matchbrackets.js',
        'addon/edit/matchtags.js',
        'addon/selection/active-line.js',
        'addon/selection/selection-pointer.js',
    ],
    'pluginOptions' => [
        'modes' => ['xml', 'javascript', 'css'],
    ]
]);

License

yii2-editors is released under the BSD-3-Clause License. See the bundled LICENSE.md for details.

yii2-editors's People

Contributors

kartik-v avatar pappfer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

yii2-editors's Issues

Console error: kv-Summernote is not a function in jQuery

Prerequisites

  • [done] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [yes ] The issue still exists against the latest master branch of yii2-editors.
  • [yes ] This is not an usage question. I confirm having read the widget documentation and demos.
  • [yes] This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • [yes ] This is not a source plugin (summernote) issue. (Those should be directed to the plugin issues repo).
  • [yes ] I have attempted to find the simplest possible steps to reproduce the issue.

Steps to reproduce the issue

  1. Used Yii2-Advance-Project Template along with Kartik Gii, Kartik Widgets and Kartik Editors
  2. Tried to use Summernote in the following way:
    <?= $form->field($model, 'long_description')->widget(Summernote::class, [ 'useKrajeePresets'=>true, 'options'=>[ 'rows'=>15 ] ]); ?>
  3. Getting the following error in browser console:
    Uncaught TypeError: jQuery(...).kvSummernote is not a function at HTMLDocument.<anonymous> (index.php?r=image-post%2Fcreate:1067:39) at e (jquery.min.js:2:30038) at t (jquery.min.js:2:30340)
    The js files are all loaded aptly, here is a snippet:
<script src="/mermaid/backend/web/assets/2f27bcb2/yii.js"></script>
<script src="/mermaid/backend/web/assets/2f27bcb2/yii.activeForm.js"></script>
<script src="/mermaid/backend/web/assets/6a5a6c2b/js/bootstrap.bundle.js"></script>
<script src="/mermaid/backend/web/assets/a1fa85fd/js/activeform.js"></script>
<script src="/mermaid/backend/web/assets/2f27bcb2/yii.validation.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.61.1/codemirror.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.61.1/mode/xml/xml.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/2.36.0/formatting.js"></script>
<script src="/mermaid/backend/web/assets/a8446441/js/kv-codemirror.js"></script>
<script src="//cdn.jsdelivr.net/npm/[email protected]/dist/summernote-bs4.js"></script>
<script src="/mermaid/backend/web/assets/a8446441/js/kv-summernote.js"></script>
<script src="/mermaid/backend/web/assets/cfc9aeea/js/kv-widgets.js"></script>
<script src="/mermaid/backend/web/assets/594fff17/js/form.js"></script>
<script src="/mermaid/backend/web/vendor/jquery/jquery.min.js"></script>
<script src="/mermaid/backend/web/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="/mermaid/backend/web/vendor/jquery-easing/jquery.easing.min.js"></script>
<script src="/mermaid/backend/web/js/sb-admin-2.min.js"></script>
<script src="/mermaid/backend/web/vendor/chart.js/Chart.min.js"></script>
<script src="/mermaid/backend/web/assets/7b3fe00c/dist/js/bootstrap.bundle.js"></script>

Expected behavior and actual behavior

When I follow those steps, I see simple textarea

I was expecting a summernote area with toolbar

Environment

Browsers

  • Google Chrome

Operating System

  • Windows

Libraries

  • jQuery version:
  • yii2-editors version: dev-master

Render problem with ajax loaded content not working Summernote editor

@kartik-v

all widgets are working on ajax loaded contents except Summernote WYSIWYG ediror

<?php


/* @var $this \yii\web\View */

/* @var $model \backend\models\Faq */

use backend\models\Faq;
use yii\bootstrap4\ActiveForm;
use yii\bootstrap4\Html;
use yii\helpers\Url;
use common\helpers\ChoiceHelper;
use kartik\select2\Select2;
use common\helpers\LanguageHelper;
use kartik\icons\FontAwesomeAsset;
FontAwesomeAsset::register($this);
use kartik\editors\Summernote;
?>

<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <?php $form = ActiveForm::begin(['id' => 'create-form', 'enableAjaxValidation' => true, 'options' => ['data-target' => 'ajax']]); ?>
        <div class="modal-header">
            <h4 class="modal-title" id="myLargeModalLabel">
                <?= $model->isNewRecord ? Yii::t('app', 'Create Faq') : Yii::t('app', 'Update Faq') ?>
            </h4>
        </div>
        <div class="modal-body">
            <div class="row">
                <div class="col-md-6">
                <?= $form->field($model, 'faq_category_id')->widget(Select2::classname(), [
                        'theme'     =>  Select2::THEME_BOOTSTRAP,
                        'data' => ChoiceHelper::getFaqCategoryChoices(),
                        'options' => [
                            'placeholder' => Yii::t('app', 'Select a category ...'),
                        ],
                        'pluginLoading' => false,
                ])?>
                </div>
                <div class="col-md-6">
                    <?= $form->field($model, 'status')->dropdownList(Faq::getEnumValues('status')) ?>
                </div>
                <div class="col-md-12">
                    <?= $form->field($model, 'title')->textInput() ?>
                </div>
                <div class="col-md-12">
                    <?php //$form->field($model, 'description')->textarea(['rows' => '6']) ?>
                    <?= $form->field($model, 'description')->widget(Summernote::classname(), [
                        'options' => ['placeholder' => 'Edit your blog content here...']
                    ]); ?>
                </div>
                <div class="col-md-6">
                    <?= $form->field($model, 'language')->widget(Select2::classname(), [
                        'theme' => Select2::THEME_BOOTSTRAP,
                        'data' => LanguageHelper::LANGUAGE_CHOICES(),
                        'hideSearch' => true,
                        'options' => [
                            'placeholder' => Yii::t('app', 'Select a language ...'),
                        ],
                        'pluginOptions' => [
                            'allowClear' => true,
                        ],
                        'pluginLoading' => false,
                    ]); ?>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <?= Html::submitButton(
                $model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Save Changes'),
                ['class' => 'btn btn-primary']
            ) ?>
            <button class="btn btn-danger" data-dismiss="modal" id="faq-close"><?= Yii::t('app', 'Close') ?></button>
        </div>
        <?php ActiveForm::end(); ?>
    </div>
</div>

<?php
$this->registerJs(<<<JS
	$('#create-form').on('ajaxSubmit',function(e, data){
	   $(this).closest('.modal').modal('hide');
	   $.pjax.reload({container: '#list_grid'});
    });
JS
) ?>

no network

there no offline! my project don't allowed to connect network.

Cannot read property defaults of undefined - Summernote

Prerequisites

  • This is not an usage question. I confirm having read the widget documentation and demos. Easy coz link is dead :-)
  • This is not a source plugin (summernote) issue. Error occurs in JS by kv - see stack dump bellow.

Steps to reproduce the issue

Very basic setup:

$form->field($model, 'category_description')->widget(Summernote::class, [
	'options' => [
		'placeholder' => 'Edit your blog content here...',
	]
])

Expected behavior and actual behavior

Wysiwyg will not initiate on textarea.

Received console error:

jquery.js:3850 Uncaught TypeError: Cannot read property 'defaults' of undefined
    at HTMLTextAreaElement.<anonymous> (kv-summernote.js:82)
    at Function.each (jquery.js:367)
    at jQuery.fn.init.each (jquery.js:202)
    at jQuery.fn.init.$.fn.kvSummernote (kv-summernote.js:79)
    at HTMLDocument.<anonymous> (list?cid=2:285)
    at mightThrow (jquery.js:3557)
    at process (jquery.js:3625)

Error in this line 82:
https://github.com/kartik-v/yii2-editors/blob/master/src/assets/lib/js/kv-summernote.js#L82

Environment

  • Google Chrome

Operating System

  • Windows

Libraries

  • jQuery version: latest = yii2 2.0.33
  • yii2-editors version: @dev - latest, installed today

Cannot use [] for reading in

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-editors.
  • This is not an usage question. I confirm having read the widget documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • This is not a source plugin (summernote) issue. (Those should be directed to the plugin issues repo).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. use PHP Version 5.6.40 on CentOS
  2. use Demo of Summernote with model and activeform:

// Usage with ActiveForm and model and default settings echo $form->field($model, 'content')->widget(Summernote::class, [ 'options' => ['placeholder' => 'Edit your blog content here...'] ]);

Expected behavior and actual behavior

PHP Compile Error:
yii\base\ErrorException - Cannot use [] for reading in /var/www/inwanet.inwatec.com/public_html/vendor/kartik-v/yii2-editors/src/assets/BaseAsset.php

Fix:
change Line 27 in the above file from:
$this->$ext[] = YII_DEBUG ? "{$file}.{$ext}" : "{$file}.min.{$ext}";

to:
$this->{$ext}[] = YII_DEBUG ? "{$file}.{$ext}" : "{$file}.min.{$ext}";

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 2.2.4
  • yii2-editors version: 1.0.1

Isolating the problem

  • This bug happens on the widget demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-editors without other plugins
  • I can reproduce this bug in a jsbin

Set Summernote plugin-specific options

Expected behavior and actual behavior

When I try to set some original Summernote options, like airMode , I get an error.
I was expecting to set this property while initializing the plugin, like this:

Summernote::widget([
  'model' => $model,
  'attribute' => 'body',
  'useKrajeeStyle' => true,
  'useKrajeePresets' => true,
  'enableFullScreen' => false,
  'enableCodeView' => false,
  'enableAirMode' => true, //or something similar
])

Maybe I am looking at the wrong place. If so, how can I set those kind of plugin settings?

Field validation error is not visible

When the summernote field get validated, the error is set in the
<div class="invalid-feedback">Mail Message non può essere vuoto.</div>
but is not visible.
Others filed's error works as expected.
When inspecting the invalid-feedback div I see that in other fields the
'display: block;'
is applied but not on the summernote fields

Using the filed as textArea works as expected, and the error is shown.

Steps to reproduce the issue

  1. add validation rules to the filed (in my case required)
  2. submit with no data

Expected behavior and actual behavior

When I follow those steps, the error is not shown

I was expecting to see the error

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox

Operating System

  • Windows

Libraries

  • jQuery version: 3.6.0
  • yii2-editors version: 1.0.1

Isolating the problem

This bug happens when using yii2-editors without other plugins

Error when first time open Bootstrap4 modal and has Summernote in it.

Prerequisites

  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • The issue still exists against the latest master branch of yii2-editors.
  • This is not an usage question. I confirm having read the widget documentation and demos.
  • This is not a general programming / coding question. (Those should be directed to the webtips Q & A forum).
  • This is not a source plugin (summernote) issue. (Those should be directed to the plugin issues repo).
  • I have attempted to find the simplest possible steps to reproduce the issue.
  • I have included a failing test as a pull request (Optional).

Steps to reproduce the issue

  1. installing yii2 editors from dev-master
  2. set bootstrap 4 param
  3. use summernote with simple form

Expected behavior and actual behavior

I try to use this plugin in bootstrap 4 modal, first time I open the modal, I get this error Uncaught TypeError: $el.summernote is not a function, but when I open the modal second time, its good..

this is the first time I open the modal
index1
Screenshot_20220114_160341

and this is the second time I open the modal, summernote working good..
index2

this is my code :

<?php
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use yii\helpers\Url;
use yii\helpers\ArrayHelper;
use kartik\editors\Summernote;
?>
<div class="data-form">
    <?php $form = ActiveForm::begin(); ?>
    <?= $form->field($model_sub_kegiatan_base, 'definisi_operasional')->widget(Summernote::class, [
            'useKrajeePresets' => true,
        ]) ?>

	<?php if (!Yii::$app->request->isAjax){ ?>
	  	<div class="form-group">
	        <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
	    </div>
	<?php } ?>

    <?php ActiveForm::end(); ?>
</div>

Environment

Browsers

  • Google Chrome
  • Mozilla Firefox
  • Internet Explorer
  • Safari

Operating System

  • Windows
  • Mac OS X
  • Linux
  • Mobile

Libraries

  • jQuery version: 3.6.0
  • yii2-editors version: dev-master

Isolating the problem

  • This bug happens on the widget demos page
  • The bug happens consistently across all tested browsers
  • This bug happens when using yii2-editors without other plugins
  • I can reproduce this bug in a jsbin

summernote editor overlapping

I am using Yii2 advance latest version 2.0.47. Bootstrap 5.
I have installed this and found that its overlapping other fields in form.

Any help?

Screenshot 2023-05-10 at 1 08 54 PM

How can i add my own custom presets

Well like the title says, how can i add a diferent preset other than KrajeePresets?

Maybe the question is dumb but i can´t see where to declare this

image

I mean, it will be cool to add the option to use the same pair-key-array to just modify some properties, for example, in my case i only want to modify the height.

summernote inside modal, problem with help window

Steps to reproduce the issue

When the summernote editor is inside a modal, opening the help and then closing it by clicking on the X dismiss both modal, while clicking outside help modal works as expected by closing only the help

Expected behavior and actual behavior

The main modal should not close

Environment

Browsers
tested in Google Chrome and Mozilla Firefox for windows

Libraries

  • jQuery version: 3.6.0
  • yii2-editors version: @dev 1.0.1

Isolating the problem

The bug happens consistently across all tested browsers
This bug happens when using yii2-editors without other plugins

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.