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,
) ,
)
) ,
));
?>
Related
I create a custom post type of name courses. For this custom post type create a dynamic dropdown meta box data is shown in dropdown but not save in db.Please check my code where i am doing wrong to save data .My meta box is showing up fine, but the data I enter is not saving. I.e. when I click 'update' on the post the meta box reverts back to my placeholder text.
if ( ! function_exists('add_courses') ) {
// Register Custom Post Type
function add_courses() {
$labels = array(
'name' => _x( 'Courses', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Course', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Courses', 'text_domain' ),
'name_admin_bar' => __( 'Courses', 'text_domain' ),
'archives' => __( 'Course Archives', 'text_domain' ),
'attributes' => __( 'Course Attributes', 'text_domain' ),
'parent_item_colon' => __( 'Parent Course:', 'text_domain' ),
'all_items' => __( 'All Courses', 'text_domain' ),
'add_new_item' => __( 'Add New Course', 'text_domain' ),
'add_new' => __( 'Add New Course', 'text_domain' ),
'new_item' => __( 'New Course', 'text_domain' ),
'edit_item' => __( 'Edit Course', 'text_domain' ),
'update_item' => __( 'Update Course', 'text_domain' ),
'view_item' => __( 'View Course', 'text_domain' ),
'view_items' => __( 'View Courses', 'text_domain' ),
'search_items' => __( 'Search Course', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
'featured_image' => __( 'Featured Image', 'text_domain' ),
'set_featured_image' => __( 'Set featured image', 'text_domain' ),
'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
'use_featured_image' => __( 'Use as featured image', 'text_domain' ),
'insert_into_item' => __( 'Insert into item', 'text_domain' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
'items_list' => __( 'Courses list', 'text_domain' ),
'items_list_navigation' => __( 'Courses list navigation', 'text_domain' ),
'filter_items_list' => __( 'Filter Courses list', 'text_domain' ),
);
$args = array(
'label' => __( 'Course', 'text_domain' ),
'description' => __( 'Add Courses', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'comments', 'trackbacks',
'revisions', 'custom-fields', 'page-attributes', 'post-formats' ),
'taxonomies' => array('post_tag'),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'show_in_rest' => true,
'register_meta_box_cb' => 'wpt_add_faculty_metaboxes',
);
register_post_type( 'course_type', $args );
// register taxonomy
register_taxonomy('courses', 'course_type', array('hierarchical' => true, 'label' => 'Course Categories', 'query_var' => true, 'rewrite' => array( 'slug' => 'course-type' )));
}
add_action( 'init', 'add_courses', 0 );
function wpt_add_faculty_metaboxes() {
add_meta_box(
'wpt_faculty_member',
'Faculty',
'wpt_faculty_member',
'course_type',
'side',
'default'
);
}
add_action( 'add_meta_boxes', 'wpt_add_faculty_metaboxes' );
function wpt_faculty_member() {
global $post;
wp_nonce_field( basename( __FILE__ ), 'event_fields' );
$faculty_roles = get_post_custom( $post->ID );
$args = array(
'role' => 'faculty',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$faculties = get_users( $args );
echo '
<select name="faculty_role" id="faculty_role">
<option value="">Select Faculty...
</option>';
foreach ( $faculties as $faculty ) :
echo '
<option value="' . $faculty->ID . '">' . $faculty->user_login . '
</option>';
endforeach;
echo '
</select>';
}
/**
* Save the metabox data
*/
add_action( 'save_post', 'wpt_save_events_meta', 1, 2 );
function wpt_save_events_meta( $post_id, $post ) {
// Return if the user doesn't have edit permissions.
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
// Verify this came from the our screen and with proper authorization,
// because save_post can be triggered at other times.
if ( ! isset( $_POST['faculty_role'] ) || ! wp_verify_nonce( $_POST['event_fields'], basename(__FILE__) ) ) {
return $post_id;
}
// Now that we're authenticated, time to save the data.
// This sanitizes the data from the field and saves it into an array $events_meta.
$events_meta['faculty_role'] = esc_textarea( $_POST['faculty_role'] );
// Cycle through the $events_meta array.
// Note, in this example we just have one item, but this is helpful if you have multiple.
foreach ( $events_meta as $key => $value ) :
// Don't store custom data twice
if ( 'revision' === $post->post_type ) {
return;
}
if ( get_post_meta( $post_id, $key, false ) ) {
// If the custom field already has a value, update it.
update_post_meta( $post_id, $key, $value );
} else {
// If the custom field doesn't have a value, add it.
add_post_meta( $post_id, $key, $value);
}
if ( ! $value ) {
// Delete the meta key if there's no value
delete_post_meta( $post_id, $key );
}
endforeach;
}
}
New solution, as of WP 3.7: save_post_{$post_type}
add_action( 'save_post_my_post_type', 'wpse63478_save' );
function wpse63478_save() {
//save stuff
}
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 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 .
I'm designing a custom adminhtml grid based on a model of my own, I've added an actions column to the grid which I'd like to be able to click to copy some text to the clipboard.
So in the _prepareColumns() function in Grid.php, I've added the actions column as seen below:
$this->addColumn('action',array(
'header' => Mage::helper('sales')->__('To Clipboard'),
'width' => '5%',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'url' => array('base'=>'*/*/toclipboard'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'is_system' => true,
)
);
I'd likely need to use Javascript to do this, but I'm not quite sure how to. Using the method above strangely enough also causes a page reload, even though I have successfully added $this->setUseAjax(true); to __construct();.
Would appreciate some input.
There are some interesting things you can do here. Mainly, you will want to reference the Action renderer and the Grid Javascript. The code you have right now should render a single link in the actions column. However, if you provide an array of actions, this will become a <select> list. When a <select> is rendered, then the grid.js file is responsible for performing the action.
Below are some examples of what you would pass in the 'actions' array:
Javascript Onclick w/ link
...
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'onclick' => 'window.location = "' . Mage::getUrl('*/*/toclipboard') . '"'
)
),
...
Confirm before running action
...
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'url' => array('base'=>'*/*/toclipboard'),
'confirm' => true
)
),
...
Render a <select> list of actions (open last action in a popup)
...
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'url' => array('base'=>'*/*/toclipboard'),
'confirm' => true
),
array(
'caption' => Mage::helper('sales')->__('Example'),
'onclick' => 'window.location = "' . Mage::getUrl('*/*/toclipboard') . '"'
),
array(
'caption' => Mage::helper('sales')->__('Popup'),
'popup' => true
'url' => array('base'=>'*/*/toclipboard'),
)
),
...
#Franklin P Strube: ty, pointed me in the right direction.
Final solution I used was as follows
....
'actions' => array(
array(
'caption' => Mage::helper('sales')->__('Copy'),
'onclick' => "javaScriptCopyMethod();"
)
),
....
It is considered bad practice to access a user's clipboard and most browsers prevent this nowadays, I did however find an extremely creative post linked below explaining how Trello "appears" to access the users' clipboard, the solution was actually posted by Daniel LeCheminant who is one of the Trello developers.
Solution: How does Trello access the user's clipboard?
Additional: https://trello.com/daniel
Simple add a option : 'target'=>'_blank'
Example :
$this->addColumn('action',
array(
'header' => Mage::helper('revocation')->__('Action'),
'width' => '100px',
'type' => 'action',
'getter' => '',
'actions' => array(array(
'caption' => Mage::helper('revocation')->__('View'),
'url' => array('base' => 'adminhtml/sales_order/view'),
'field' => 'order_id',
'target'=>'_blank'
)),
'filter' => false,
'sortable' => false,
'index' => 'order_id',
));