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

Fix for use with ajax post #3

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions Jsoneditor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use yii\helpers\BaseInflector;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\JsExpression;
use yii\widgets\InputWidget;

class Jsoneditor extends InputWidget
Expand Down Expand Up @@ -41,17 +42,20 @@ public function run()
$view = $this->getView();
JsoneditorAsset::register($view);
$editorName = BaseInflector::camelize($this->id) . 'Editor';
// Add possible user defined change function to ActiveField update method
$this->editorOptions['change'] = new JsExpression(
"function() {".
"jQuery('#" . $this->id . "').val(" . $editorName . ".getText());" .
(isset($this->editorOptions['change'])?$this->editorOptions['change']:'') .
"}"
);
$view->registerJs(
"var container = document.getElementById('" . $this->options['id'] . "');
var options = " . Json::encode($this->editorOptions) . ";
var options = " . Json::encode($this->editorOptions). ";
var json = " . $this->value . ";
" . $editorName . " = new JSONEditor(container, options, json);
jQuery('#" . $this->id . "').parents('form').eq(0).submit(function() {
jQuery('#" . $this->id . "').val(" . $editorName . ".getText());
return true;
});"
" . $editorName . " = new JSONEditor(container, options, json);"
);
echo Html::hiddenInput($this->name, $this->value, ['id' => $this->id]);
echo Html::tag('div', '', $this->options);
}
}
}