I have a dropdown menu, that has a onchange function. Once the function is executed it changes another dropdown menu.
I need to make it so it executes the script onload.
1st dropdown:
echo $form->field($model, 'company_id')->dropDownList($items_company, ['prompt' => 'Select Company', 'style' => 'width:400px;', 'onchange' => '
$.post("index.php?r=project/lists&id=' . '"+$(this).val(), function( data ) {
$( "select#project-client" ).html( data );
console.log("On change");
console.log(data);
});
',])->label('Company');
2nd dropdown:
echo '<label class="control-label">Company Client</label>';
echo Select2::widget([
'model' => $model,
'attribute' => 'client',
'theme' => Select2::THEME_BOOTSTRAP,
'options' => [ 'label' => 'Client',
'multiple' => true, 'style' => 'width:400px;', 'overwriteInitial' => true],
'pluginOptions' => [
'disabled' => false,
],
]);
This is what I tried:
$(document).ready(function () {
var currentProjectCompany = $('#project-company_id').val();
$.post("index.php?r=project/lists&id=' . '" + currentProjectCompany, function (data) {
$("select#project-client").html(data);
console.log("Company ID:");
console.log(currentProjectCompany);
console.log("Clients");
console.log(data);
});
});
Move the onchange code into its own function (it should be there anyway), and execute that function in the ready() function.
That way it will fire both onchange and onload.
I do the same check my code it may help you .But i use ajax and jquery.
For firs dropdown .
echo $form->dropDownListGroup(
$model 'id', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' => abc::getName($model->id),
'htmlOptions' => array(
'prompt' => 'Select Project',
'ajax' => array(
'type' => 'POST',
'url' => ( Yii::app()->createUrl('/' . $domain_name . '/qq/xyz/abc') ),
'update' => '#seconddropdownid',
//'dataType' => 'json',
'data'=>array('id'=>'js:this.value'),
)
),
),
)
);
in second dropdown :
echo $form->dropDownListGroup(
$project, 'tag', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' =>$this->getProjectTags(),
'htmlOptions' => array(
'prompt' => 'Select Tags',
),
)
)
);
on change of the second list you can update the the list-view of yii .
Related
I need to add multiple JS file in using king composer.
I follow Add Map
but could not load multiple files.
Code is use for WordPress theme option for show map on selection page.
<?php
$kc->add_map(array(
'location' => array(
'name' => 'Locations',
'description' => 'Add your location details',
'icon' => 'cpicon kc-icon-map',
'category' => 'Content',
'assets' => array(
'scripts' => array(
'googlemap_js' => "MY JS FILE PATH",
'type' => 'javascript',
'jquery' => '',
) ,
'scripts' => array(
'location_js' => 'MY JS FILE PATH',
'type' => 'javascript',
'jquery' => '',
) ,
) ,
'params' => array(
array(
'name' => 'image',
'label' => 'Upload Images',
'type' => 'attach_images',
'admin_label' => true,
) ,
)
) ,
));
?>
You are using wrong ways to add the scripts;
It must be
<?php
$kc->add_map(array(
'location' => array(
'name' => 'Locations',
'description' => 'Add your location details',
'icon' => 'cpicon kc-icon-map',
'category' => 'Content',
'assets' => array(
'scripts' => array(
'googlemap_js' => "MY JS FILE PATH",
'location_js' => 'MY JS FILE PATH',
'js_lib1' => 'MY JS FILE PATH',
'js_lib2' => 'MY JS FILE PATH',
'jquery' => '', //calling the script enqueue before - enqueue from other place.
) ,
) ,
'params' => array(
array(
'name' => 'image',
'label' => 'Upload Images',
'type' => 'attach_images',
'admin_label' => true,
) ,
)
) ,
));
?>
I want to add 21 checkboxes and a text field(Name) in a good design way. Also there must be "check all button" to check all the checkboxes, how to do it in module PHP page in prestashop.
Since I am new to prestashop I don't know about the form submission, I have to save these two fields together as a json array in database.
Is that possible in prestashop? please help me regarding this.
prestashop version = 1.6
Thanks in advance
Sample code
protected function getConfigForm()
{
return array(
'form' => array(
'legend' => array(
'title' => $this->l( 'Generate Export Order Settings' ),
'icon' => 'icon-cogs'
),
'input' => array(
array(
'type' => 'checkbox',
'name' => 'display',
'values' => array(
'query' => array(
array(
'id' => 'all_fields',
'name' => $this->l('All Fields'),
'val' => '1'
),
),
'id' => 'id',
'name' => 'name'
)
),
),
'submit' => array(
'title' => $this->l( 'Save Export Settings' ),
'class' => 'button pull-right',
'name' => 'save-main-display-settings',
)
),
);
}
I don't know how to add check box in 3 columns and 7 rows and select all button to select all the checkbox.
You can use the following JS code to add check all functionality:
$('.chk_boxes').click(function(){
var chk = $(this).attr('checked')?true:false;
$('.chk_boxes1').attr('checked',chk);
});
Fiddle here: http://jsfiddle.net/HBGzy/
I have pasted this code in my main function.php and it works great
but I want to add an image to my woocommerce product and I do not know how I can achieve that. Does anyone have an idea for doing it?
function woo_add_custom_general_fields() {
global $woocommerce, $post;
woocommerce_wp_text_input(
array(
'id' => 'telnr',
'label' => __( 'Nr. Tel)', 'woocommerce' ),
'placeholder' => 'Nr',
'desc_tip' => 'true',
'description' => __( 'tel nr.', 'woocommerce' )
)
);
}
function woo_add_custom_general_fields_save( $post_id ){
$woocommerce_telnr = $_POST['telnr'];
if( !empty( $woocommerce_telnr ) )
update_post_meta( $post_id, 'telnr', esc_html( $woocommerce_telnr ) );
}
This is what I tried and which fails:
function woo_options_add($options) {
// This is a option heading
$woo_metaboxes = array(
"image" => array (
"name" => "image",
"label" => "Post Image",
"type" => "upload",
"desc" => "Upload file hereā¦"
)),
// Return new options
return $options;
}
I have data in Drop down list as per role(for every role table are different).
I don't have any idea how to do because I am not familiar with yii2 First select a role and after selecting role I want data from different different table as per role
<?= $form->field($model, 'role')->dropDownList( [ 'A' => 'Admin', 'M' => 'Member', 'P' => 'Practice', ],['prompt'=>'--Select a Role--',]);?>
<?= $form->field($model, 'code')->dropDownList(
ArrayHelper::map(Member::find()->all(), 'id', 'memberCode'),
['id'=>'memberCode']
);
?>
You Need to update your 2nd dropdown when you select any value from dropdown 1st. Lets say 2nd drop down have id #dropdown2 so, i dit in yii you can change it according to yii2.
echo $form->dropDownListGroup(
$model, 'id', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' => CSystemGenerated::getProjectName($model->c_id),
'htmlOptions' => array(
'prompt' => 'Select Project',
'ajax' => array(
'type' => 'POST',
'url' => your url,
'update' => '#dropdown2',
//'dataType' => 'json',
'data'=>array('id'=>'js:this.value'),
)
),
),
)
);
<?php
echo $form->dropDownListGroup(
$model, 'tag', array(
'wrapperHtmlOptions' => array(),
'widgetOptions' => array(
'data' =>$this->getTags(),
'htmlOptions' => array(
'prompt' => 'Select Tags',
),
)
)
);
?>
check this link it will help you more.
Link1
link2
Please Refer to Kartik Dependent Drop Down in Yii2 ..This will surely helpfull
I'm trying to add custom tag to cakephp form input but it won't apply.
I am using Bootstrap switch
My code :
$this->Form->input('item_id', array(
'multiple' => 'checkbox',
'div' => false,
'data-label-text' => $items,
'class' => 'form-control',
));
att: i want to add item names as a 'data-label-text'
this is working (with out other attributes)
$this->Form->checkbox('aaa', array('data-label-text'=>'new item out'));
Any idea ? help ?
Try this
$options = array(0 => 'new item out 1', 1 => 'new item out 2');
echo $this->Form->input('item_id', array(
'multiple' => 'checkbox',
'div' => false,
'options' => $options,
'class' => 'form-control',
));