Closed jason-son closed 10 years ago
You need to use a JsExpression
'file_browser_callback'=> new yii\web\JsExpression("function(field_name, url, type, win) {
if(type=='image') $('#my_form input').click();
}"),
tonydspaniard THANKS!!!
Thank you so much!!!
Any chance you could post your view, model and controller parts? Seems that there is a lack of resource when integrating uploads to WYSIWYG editors in Yii2. Thanks in anticipation.
@SpbSprut @Zneiat if you guys do as requested by @daro16 I would highly recommend to add the sample to the README file. Would be highly appreciated! I am lacking of time to do all the support it requires ;)
Hi Guys @SpbSprut @Zneiat, I'm attempting to implement but browse button does not trigger? any hints would be greatly appreciated.
@daro16 check if the form used for file upload is outside ActiveForm's form tags. Otherwise It will not work (form inside a form :)
Also consider csrf token. My final code is
field inside ActiveForm
<?= $form->field($model, 'text')->widget(TinyMce::className(), [
'options' => ['rows' => 10],
'clientOptions' => [
'plugins' => [
"advlist autolink lists link charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste image"
],
'toolbar' => "undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image",
'file_browser_callback'=> new yii\web\JsExpression("function(field_name, url, type, win) {
if(type=='image') {
$('#upload_image input[type=\"file\"]').click();
}
}"),
]
]) ?>
and form (outside ActiveForm!)
<form id="upload_image" action="<?=Url::to('/test/image-upload')?>" target="test-text_ifr" method="post" enctype="multipart/form-data" style="width:0px;height:0;overflow:hidden">
<input name="image" type="file" onchange="$('#upload_image').submit();this.value='';">
<input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken()?>" />
</form>
Thank you @diego-betto very kind.
I follow the documents and here http://pixabay.com/zh/blog/posts/direct-image-uploads-in-tinymce-4-42/
but not work,errors occurs when I click the upload button: