CGI combo Cant select the right value - cgi

my cgi popup menu only selects the first element of the array of values. This is the code for its creation :
$q->popup_menu({
-id=> 'id',
-name => 'name',
-class => 'comboClass',
-values => [#aArray1],
-labels => \%aArray2
});

Try to remove [] and to add \:
-values => [#aArray1],
To
-values => \#aArray1,

Related

Prestashop 1.6.1 Helper Form fields undefined index

I'm struggling with this for quite some hours:
I'm trying to add new fields to a form generated with the HelperForm class in Prestashop for a custom module.
I try to do this for the configuration page of the module in the getContent() function
The following field is accepted and it works:
array(
'type' => 'file',
'label' => $this->l('Button image'),
'id' => 'button_image_path',
'name' => 'button_image_path',
'image' => '<img src="'._MODULE_DIR_.$this->name.'\\img\\'.basename($buttonImage["setting_value"]).'" class="button-image-preview" width="30">'
)
However, when i try to add other fields like this:
array(
'type' => 'text',
'label' => $this->l('Number of displayed products'),
'name' => 'CROSSSELLING_NBR',
'desc' => $this->l('Set the number of products displayed in this block.'
)
It gives this error:
Notice on line 387 in file D:\wamp\www\qmart.ro\tools\smarty\sysplugins\smarty_internal_templatebase.php(157) : eval()'d code
[8] Undefined index: CROSSSELLING_NBR
However, the input is still generated, and it looks like this:
<input type="text" name="CROSSSELLING_NBR" id="CROSSSELLING_NBR" value="" class="">
What i tried:
Changing the input type from text to color for example, and it gave the same error
Changing the label content and the name content, and the error still appeared
I did not change anything in the core files.
So, the form is being built for those inputs, but this "undefined index" thing still occurs.
So, apparentply they force you to choose some default value for the inputs.
i simplu solved it by adding this line:
$helper->fields_value['CROSSSELLING_NBR'] = '';
According to your code...
array(
'type' => 'text',
'label' => $this->l('Number of displayed products'),
'name' => 'CROSSSELLING_NBR',
'desc' => $this->l('Set the number of products displayed in this block.'
)
You have an error in 'desc', you need close the final parenthesis, this should works...
array(
'type' => 'text',
'label' => $this->l('Number of displayed products'),
'name' => 'CROSSSELLING_NBR',
'desc' => $this->l('Set the number of products displayed in this block.')
)

Yii 2.0 Select Pre-selected values from Database

I have been trying to fix an issue but to no avail but i am sure i will find a solution here. I am using Kartik 2.0 Select extension to do a multiple select. Fine, all working when inserting into the database but i am unable to retrieve the saved records to be displayed as selected back in the select field.
//I have included the kartik widgets already
use kartik\widgets\Select2;
<label>Desired Specialization(s)</label>
<?= $form->field($spec, 'id')->label(false)->widget(Select2::classname(), [
'data' => $model->getAllSpecializations(),
'options' => ['placeholder' => 'You can choose more than one specialization ...'],
'pluginOptions' => [
'allowClear' => true,
'multiple' => true
],
]);
?>
</div>
Please, your reply will be appreciated. Thanks
I think you need to add the saved values as the initial data? Like so:
'value' => $savedDataArray, // initial value
http://demos.krajee.com/widget-details/select2#usage-tags
After much digging into the code, i found a way on how to display selected database values into a multi-select option using Yii Select2
My Model
public function getCandidateLanguage()
{
$langValues = (new \yii\db\Query())
->select('c.language_id AS id, l.lang_name')
->from('candidate_language c ')
->innerJoin('languages l','c.language_id = l.id')
->where('c.candidate_id='.$this->candidate_id)
->orderBy('c.language_id')
->all();
return \yii\helpers\ArrayHelper::map($langValues,'id','lang_name');
}
My View
use kartik\widgets\Select2;
<?php
//the line below is to fetch the array key of $model->getCandidateLanguage() array
$lang->id = array_keys($model->getCandidateLanguage()); // value to initialize
echo Select2::widget([
'model' => $lang,
'attribute' => 'id',
'data' => $model->getAllLanguages(),
'options' => ['placeholder' => 'Choose multiple languages'],
'pluginOptions' => [
'allowClear' => true,
'multiple' => true,
'tags' => true,
],
]);
?>
Hope it help someone who is facing the same issue.

how to integrate multimodelform with echmultiselect yii?

I am running into a little snag with combining extensions "EchMultiSelect" and "MultiModelForm" of YII framework.
What I'm trying to do is copy a set of form elements one of which elements is an EchMultiSelect widget.
According to tutorial on the jqRelCopy page, I would need to pass a copy of the element (datePicker in their example) to the 'jsAfterNewId' option:
'jsAfterNewId' => JQRelcopy::afterNewIdDatePicker($datePickerConfig),
So, I tried to modify that to:
'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
Where I also added the following to MultiModelForm.php:
public static function afterNewIdMultiSelect($element)
{
$options = isset($element['options']) ? $element['options'] : array();
$jsOptions = CJavaScript::encode($options);
return "if(this.attr('multiple')=='multiple'){this.multiselect(jQuery.extend({$jsOptions}));};";
}
its copied and working properly when i am using Add Person link but what happens if i am adding/cloning three items for example and when i change the third item multiselct option then its reflecting to the first multiselect dropdown only this is same for other as well also when i am adding new items by clicking on the Add Person link then its cloning the same element to the new row item
here is the code for the form configuration variables and multimodel widget call.
//$userList=array of the userIds from users table
$memberFormConfig = array(
'elements'=>array(
'userId'=>array(
'type'=>'ext.EchMultiSelect.EchMultiSelect',
'model' => $User,
'dropDownAttribute' => 'userId',
'data' => $userList,
'dropDownHtmlOptions'=> array(
'style'=>'width:500px;',
),
),
...
...
));
calling the MultiModelForm widget from the same view file
$this->widget('ext.multimodelform.MultiModelForm',array(
'id' => 'id_member', //the unique widget id
'formConfig' => $memberFormConfig, //the form configuration array
'model' => $model, //instance of the form model
'tableView' => true,
'validatedItems' => $validatedMembers,
'data' => Person::model()->findAll('userId=:userId', array(':userId'=>$model->id)),
'addItemText' => 'Add Person',
'showAddItemOnError' => false, //not allow add items when in validation error mode (default = true)
'fieldsetWrapper' => array('tag' => 'div',
'htmlOptions' => array('class' => 'view','style'=>'position:relative;background:#EFEFEF;')
),
'removeLinkWrapper' => array('tag' => 'div',
'htmlOptions' => array('style'=>'position:absolute; top:1em; right:1em;')
),
'jsAfterNewId' => MultiModelForm::afterNewIdMultiSelect($memberFormConfig['elements']),
));
Can someone help me with this please?
Thanks in advance!
After a long searching and googleing i found the solution for this, just replace the function in your MultiModelForm.php:
public static function afterNewIdMultiSelect($element)
{
$options = isset($element['options']) ? $element['options'] : array();
$jsOptions = CJavaScript::encode($options);
return "if ( this.hasClass('test123456') )
{
var mmfComboBoxParent = this.parent();
// cloning autocomplete and select elements (without data and events)
var mmfComboBoxClone = this.clone();
var mmfComboSelectClone = this.prev().clone();
// removing old combobox
mmfComboBoxParent.empty();
// addind new cloden elements ()
mmfComboBoxParent.append(mmfComboSelectClone);
mmfComboBoxParent.append(mmfComboBoxClone);
// re-init autocomplete with default options
mmfComboBoxClone.multiselect(jQuery.extend({$jsOptions}));
}";
}
Thats It....!!
Thanks...!!!

Get images by custom field

I'm trying to display all images that have a certain custom field from the types plugin set to true. It would also work to filter them by post_content or post_excerpt but none of my attempts have worked so far.
<?
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_content' => 'foo',
'numberposts' => -1
);
?>
<? print_r(get_posts($args)); ?>
This get's all images allthough only one has the post_content foo. My attempt to use WP_Query failed miserably as well.
Any help is appreciated!
WP_Query method :
$args = array(
'post_type' => 'attachment',
'post_status' => 'inherit',
'meta_query' => array(
array(
'key' => 'color',
'value' => 'blue',
'compare' => 'LIKE',
),
),
);
$query = new WP_Query( $args );
I am presuming that the reason why you failed with WP_Query is due to the following condition.
Codex states : The default WP_Query sets 'post_status'=>'publish', but attachments default to 'post_status'=>'inherit' so you'll need to explicitly set post_status to 'inherit' or 'any' as well.
http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters
get_posts method :
$args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'meta_key' => 'custom-field',
'meta_value' => 'custom value',
'numberposts' => -1
);
print_r(get_posts($args));
The only draw back with this method is that the meta_value needs to exactly match what was entered in the custom field. If you still like to use get_posts then use the meta_query as shown in WP_Query example above.

yii tokeninput extension cursor focus on wrong place after same match?

I am having problem with yii tokeninput extension. When i search name it gives the user list and if i select any name and if that name is also selected previous than the cursor point after the selected item, it does not point at the end of all the the item in the input box.
I am using this configuration.
$this->widget('ext.tokeninput.TokenInput', array(
'model' => $model,
'attribute' => 'USER_ID',
'url'=>$this->createUrl('user/searchUserNames'),
'options' => array(
'allowCreation' => false,
'preventDuplicates' => true,
// 'resultsFormatter' => 'js:function(item){ return “<li><p>” + item.name + “</p></li>” }',
'theme' => 'facebook',
//'hintText' => 'Type',
'prePopulate' => $prePopulate,
'processPrePopulate' => $processPrePopulate,
)
));
I have also lookout at the examples but does not find the solution. can any one help me ?
Loopj: jquery token input demo
plz comment the line number 509 in **jquery.tokeninput.js**
input_token.insertAfter(found_existing_token);
that line insert cursor after that selected item so if you comment
this line cursor is at the end of all names