Yii2 - Multiple Dropzone Widget doesn't work - yii

I'm working with Yii2 to develop an intranet portal.
I have to put multiple widget in same page but it doesn't work.
Give me this error
Dropzone already attached.
And my code is
...
<?= \kato\DropZone::widget([
'id' => 'dzImages',
'dropzoneContainer' => 'dzImages',
'options' => [
'url' => 'index.php?r=orders/upload&uid='.$model->ref,
'maxFilesize' => '10',
'acceptedFiles' => "image/*",
],
]); ?>
</p>
<p>
<?php echo \kato\DropZone::widget([
'id' => 'dzPDF',
'dropzoneContainer' => 'dzPDF',
'options' => [
'url' => 'index.php?r=orders/uploadpdf&uid='.$model->ref,
'maxFilesize' => '10',
'acceptedFiles' => ".pdf",
],
]);
?>
</p>
...
How can i resolve it?

Looking at the code of the widget, the 'id' parameter seems to be used differently than one would expect, instead you should probably set previewsContainer property too.
The ID parameter seems to be used as a JavaScript variable here:
https://github.com/perminder-klair/yii2-dropzone/blob/41e8145d940cc9955011138a9f16ad80e9831423/DropZone.php#L75

Related

How to hide a raw in view.php file using Yii2 Framework

I have this raw in my view.php file:
[
'attribute' => 'Descrizione',
'format' => 'html',
'value' => function ( $model ) {
return nl2br($model->Descrizione);
},
'label' => 'Descrizione',
],
What I want is to hide the entire field if the value don't contains any character, so if is = "" OR is NULL. So I want to hide the entire field "Descrizione".
Which is the option that I have to add in this code?
Thank you very much
You can use the options attribute to set a CSS style.
for example:
empty($model->Descrizione)?'hidden':''
https://www.yiiframework.com/doc/api/2.0/yii-widgets-activefield
Eg:
<?= $form->field($model, 'Descrizione',['options'=>['class'=>empty($model->Descrizione)?'hidden':'']])->textInput(['maxlength' => true, 'disabled' => true]) ?>
Make sure the class "hidden" is actually defined - if you are using bootstrap you can use d-none
Are you using Gridview or DetailView ?
If DetailView, try :
[
'attribute' => 'Descrizione',
'label' => 'Descrizione',
'visible' => !empty($model->Descrizione),
'format' => 'ntext',
],

How to create a ZF2 FormCollection of the Doctrine ORM Module's ObjectSelect elements?

I have an odd situation where my add form works perfectly, but the edit form will not even load. Instead I get the following error:
Notice: Undefined property: DoctrineModule\Form\Element\ObjectSelect::$object in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
Fatal error: Class name must be a valid object or a string in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
I have objects of the class Application\Model\Record which have a many-to-many relationship to objects of the class Application\Model\Subject. I want the Subjects to appear as dropdowns in the Record forms, with the option to add multiple Subjects. So in the RecordFieldset.php I have:
$this->add(array(
'name' => 'subjects',
'type' => 'Zend\Form\Element\Collection',
'options' => array(
'label' => 'Subjects',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'allow_remove' => true,
'template_placeholder' => '__subjectindex__',
'target_element' => array (
'name' => 'subject',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'options' => array(
'object_manager' => $this->objectManager,
'target_class' => 'Application\Model\Subject',
'property' => 'name',
'empty_option' => 'Select a subject',
),
'attributes' => array(
'class' => 'form-control',
),
),
),
));
And like I said, this works perfectly in the Record add form. But it looks like on the edit form it cannot load the Subjects. Has anyone else tried something like this? Or do you have an idea what the error is saying?
Environment:
Zend Framework 2.3.3
Doctrine-orm-module 0.8.0
Doctrine 2.4.2
Looks like this is a bug on ZF2, target elements need to be a fieldset for it to work otherwise it will run into this issue. Use a fieldset to wrap the ObjectSelect.

CClientScript duplicates the output

I'm trying to use this extension in a partial view, in my registration module...
$form->widget('ext.tokenInput.TokenInput', array(
'model' => $model,
'attribute' => 'tags',
'url' => array('wizard/search'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
'allowFreeTagging' => false,
'minChars' => 2,
'theme' => 'facebook',
)
));
...and assets (javascript and CSS files) are duplicated.
Basically I can see in the HTML code multiple occurrences of these files.
I have the same problem if I try to add custom JS files in the same partial view.
I specify POS_HEAD and I can see the code in <head> and in the middle of the page.
Why CClientScript duplicates assets if I add them in a partial view?
Thanks a lot!

in yii how to perform dynamic validation based on the dropdown choice

Hello everybody and thansk for reading .
Iam making a website just for fun and to learn yii. The website is a app that can be used for reporting pirated links.
I have an input filed in which i provide a link and than i have a dropdown menu from where you can select the type of link you are submitting. Depending on the value you select i want different validation rules to perform on the link submitted. If i was not clear in my explenation feel free to visit www.youtubetv.it , on the main page you will see a input field and a dropdown.
The code is as follows ;
<div class="span4">
<div class="input-prepend"><span class="add-on" style="height: 50px;">
<i class="icon-4x icon-globe" style="line-height: 54px;"></i></span>
<?php
echo $form->textField($model, 'link', array(
'prepend' => '<i class="icon-4x icon-globe" style="line-height: 54px;"></i>',
'class' => 'span12', 'maxlength' => 999,
'style' => 'height:60px;font-size: 22px;width: 400px;',
));
?>
</div>
</div>
<div class="span4 offset1">
<?php
echo $form->dropDownList($model, 'category', CHtml::listData(Lookup::model()->findAll('type="kind"'), 'code', 'name'), array(
'prompt' => 'Select Type',
'class' => 'span12',
'style' => 'height:60px;font-size: 22px;',
));
?>
</div>
Current validation rules in the model
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('category, link', 'required'),
array('id_user', 'numerical', 'integerOnly' => true),
array('link', 'length', 'max' => 999),
array('link', 'url',
'allowEmpty' => false,
'defaultScheme' => null,
//'pattern' => 'esspressione regolare',
'message' => 'The specified model does not exist.',
'validSchemes' => (array('http', 'https'))
),
array('category, web_page', 'length', 'max' => 255),
array('creation_date', 'default',
'value' => new CDbExpression('NOW()'),
'setOnEmpty' => false,
'on' => 'insert'),
array('id_public_link, category, id_user, link, creation_date', 'safe', 'on' => 'search'),
);
}
I would be grateful if someone could show me an example of how i could validate the "url" if someone selects Movie from the dropdown list.
please feel free to ask for clarification if i was not clear
Yii has so called scenario for validation rules, what you need is to add 'on' key with any scenario name you like as a value in a rule you want. And then set scenario for your model as $model->scenario = 'Your scenario';
e.g.
public function rules() {
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('category, link', 'required'),
array('id_user', 'numerical', 'integerOnly' => true),
array('link', 'length', 'max' => 999),
array('link', 'url',
'allowEmpty' => false,
'defaultScheme' => null,
//'pattern' => 'esspressione regolare',
'message' => 'The specified model does not exist.',
'validSchemes' => (array('http', 'https')),
'on'=>'urlcheck'
),
array('category, web_page', 'length', 'max' => 255),
array('creation_date', 'default',
'value' => new CDbExpression('NOW()'),
'setOnEmpty' => false,
'on' => 'insert'),
array('id_public_link, category, id_user, link, creation_date', 'safe', 'on' => 'search'),
);
}
And then in your action use:
...
$type = isset($_POST['Lookup']['type'])?$_POST['Lookup']['type']:false;
if($type === '1') //as I assume from your website '1' is a Movie
$model->scenario = 'urlcheck';
...
Btw, as you can see you already have a scenario in your rule on a 'creation_date' attribute. Scenation 'insert' is default scenarion for a new records. There more default scenarions in Yii you can learn at here

Yii CListView summary text

Is there any way to hide "Summary" for CListView without loosing pagination. By summary i mean text like "Displaying 1-2 of 2 result(s).". Or maybe I should use different widget?
Try the following to get more control over the look of your CListView output:
'template'=>'{items} {pager}'
You can even use HTML in the template.
Ok, I didn't get it at first, when looking into CListView code, but setting 'summaryText' to '' will do the work. I've realised that second time when I was staring at $summaryText === null
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'itemView'=>'_indexview',
));
Here is the example for CListView:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'ajaxUpdate' => false,
'emptyText' => 'No records found.',
'summaryText' => "{start} - {end} из {count}",
'template' => '{summary} {sorter} {items} {pager}',
'sorterHeader' => 'Sort by:',
'sortableAttributes' => array('title', 'price'),
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'cssFile' => '/css/pager.css',
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'prevPageLabel'=>'←',
'nextPageLabel'=>'→',
'header'=>'Pages: ',
),
));
You should try this:
'summaryText' => FALSE,
You may hide it by adding CSS in the page like below.
<style>
.summary{
display:none;
}
</style>
Here is my suggestion
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $best_seller_data,
'itemView' => 'alsoBestseller',
'summaryText'=>false,
));