I'm having some troubles printing a 'node/add' form in a lightbox.
I have in my custom.module a hook_menu like this:
$items['get-form/%'] = array(
'title' => t('Get a form'),
'description' => t('Get form'),
'page callback' => '_get_form',
'page arguments' => array(1),
'access arguments' => array('access content'),
'type' => MENU_CALLBACK,
);
... where % is the id, like "story_node_form".
Then, I have the callback function like this:
function _get_form($form_id){
module_load_include('inc', 'node', 'node.pages');
if (strpos($form_string, "_node_form")){
//Test if the form is a <type>_node_form. Is the node/add/<type>
$content_type = explode("_node_form", $form_id)[0];
print drupal_render(node_add($content_type));
}
The forms shows right, in the lightbox. The problem is that the javascript of the form (wysiwyg, node references, term references, ...) doesn't work.
I tried to execute Drupal.attachBehaviors(), Drupal.attachBehaviors(document) and Drupal.attachBehaviors("#story-node-form") but nothing seems to work.
Anyone can help?
This code should do the trick:
function _get_form($form_id){
global $user;
$node = (object) array(
'uid' => $user->uid,
'name' => (isset($user->name) ? $user->name : ''),
'type' => 'ENTER NODE TYPE HERE',
'language' => LANGUAGE_NONE
);
$form_state['build_info']['args'] = array($node);
form_load_include($form_state, 'inc', 'node', 'node.pages');
echo drupal_render(drupal_build_form($form_id, $form_state));
}
You will need to get the node type as well as the form_id for this to work but that shouldn't be to difficult.
Related
I have multiple select elements, and each select form is either a block type or a block content. So in total i have around 10 select elements, 5 of which are block type and 5 are block content. The select options of block content will be determined by what the user select in block type.
I have 3 arrays (property, blogs, message), which have the values needed for block content.
So what i need to do is-
check what the user has selected for block type- which i have done.
Populate the block content with the relevant values- this is where i am having problems.
Here is my javascript code so far
$(".blockTypeWrapper .blockType").change(function() {
var currentBlock = $(this).val();
var blockContent = $(this).parent().siblings('.blockContentWrapper .blockContent');
if (currentBlock == '1') {
var option = document.createElement("option");
var propertyData = <?php echo $properties; ?>;
$.each(propertyData, function() {
options.append(new Option(option.text, option.value));
});
};
if (currentBlock == '2') {
$(this).siblings(".blockContent").addClass("active");
};
if (currentBlock == '3') {
$(this).siblings(".blockContent").addClass("active");
};
});
Ignore the currentBlock == '2' and 3 code, i am just trying to get it working for one first.
If there are any other easier way of achieving this then i'm all ears.
EDIT
echo $this->Form->input('main_block_type',
array(
'options' => array(
1 => 'Property',
2 => 'Blogs',
3 => 'Message'
),
'label' => 'Main Block Type',
'empty' => 'Please Select',
'class' => 'blockType',
'div' => array(
'class' => 'blockTypeWrapper'
)
)
);
echo $this->Form->input('main_block',
array(
'options' => $blogs,
'label' => 'Main Block Content',
'empty' => 'Please Select',
'class' => 'blockContent',
'div' => array(
'class' => 'blockContentWrapper'
)
)
);
Thanks
You can't access Array with echo. You need to access with:
<?php echo json_encode($properties); ?>;
try below code:
if (currentBlock == '1') {
var propertyData = <?php echo json_encode($properties); ?>;
$(".blockContent").empty(); // You can remove all the options by using empty() function.
$.each(propertyData, function (i, item) {
$('.blockContent').append($('<option>', {
value: item.value,
text: item.text
}));
});
}
PHP Array of properties should be like this:
$properties = array(
'item1' => array('text' => 'item1 text', 'value' => 'item 1 value'),
'item2' => array('text' => 'item2 text', 'value' => 'item 2 value'),
'item3' => array('text' => 'item3 text', 'value' => 'item 3 value')
);
I am having a problem getting a custom query to alphabetize. It keeps defaulting to displaying in the order of the date it was posted. Below is my php function.
function json_info2() {
// The $_REQUEST contains all the data sent via ajax
if ( isset($_REQUEST) ) {
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
// get values for all three drop-down menus
$status = $_REQUEST['status'];
$industry = $_REQUEST['services'];
$state = $_REQUEST['state'];
// array of values for each of the three drop-downs
$statusAll = array('complete','incomplete');
$industryAll = array('mining','textile','machinery');
$statesAll = array('SC','TX','WA');
// set $statusArray dependent on whether or not "all" is selected in the dropdown menu
if($status == "all") {
$statusArray = array( 'key' => 'status', 'value' => $statusAll, 'compare' => 'IN');
} else {
$statusArray = array( 'key' => 'status', 'value' => $status, 'compare' => '=');
}
if($industry == "all") {
$industryArray = array( 'key' => 'industry', 'value' => $industryAll, 'compare' => 'IN');
} else {
$industryArray = array( 'key' => 'industry', 'value' => $industry, 'compare' => '=');
}
if($state == "all") {
$stateArray = array( 'key' => 'state', 'value' => $statesAll, 'compare' => 'IN');
} else {
$stateArray = array( 'key' => 'state', 'value' => $state, 'compare' => '=');
}
$pages = array(
'post_type' => 'page',
'orderby' => 'title',
'order' => 'ASC',
'paged' => $paged,
'posts_per_page' => 5,
'meta_query' => array(
'relation' => 'AND',
$statusArray,
$industryArray,
$stateArray,
array(
'key' => '_wp_page_template',
'value' => 'template-individual-project.php',
'compare' => '='
)
)
);
// query results by page template
$my_query = new WP_Query($pages);
if($my_query->have_posts()) :
while($my_query->have_posts()) :
$my_query->the_post();
<li>
<?php the_title(); ?>
</li>
<?php
endwhile;endif;
wp_reset_query();
} // end of isset
?>
<?php
die();
}
add_action( 'wp_ajax_json_info2', 'json_info2' );
add_action( 'wp_ajax_nopriv_json_info2', 'json_info2' );
?>
This above function is called by the ajax function that follows:
function do_ajax() {
// Get values from all three dropdown menus
var state = $('#states').val();
var markets = $('#markets').val();
var services = $('#services').val();
$.ajax({
url: ajaxurl,
data: {
'action' : 'json_info2',
'state' : state,
'status' : markets,
'services' : services
},
success:function(moredata) {
// This outputs the result of the ajax request
$('#project-list').html( moredata );
$('#project-list').fadeIn();
}/*,
error: function(errorThrown){
var errorMsg = "No results match your criteria";
$('#project-list').html(errorMsg);
}*/
}); // end of ajax call
} // end of function do_ajax
Is there something simple that I'm missing here? I have a similar custom query on the page when it loads (although that initial load query doesn't have the select menu values as args), and they display in alphabetical order just fine. It's only after the ajax call to filter the list that they are no longer in order.
I have found the issue after googling the problem for quite a while. I read that some of the people who were having this problem found that their theme was using a plugin called Post Types Order. It overrides the ability to set the orderby arg.
I looked at the plugins, and sure enough, Post Types Order was there. Everything I read said that the problem could be solved by unchecking "auto sort" in the settings for the plugin. However, I did that, and orderby still didn't work. I had to completely deactivate the plugin to get orderby title to work.
This is how data is passed.
$items[] = array(
'title' => 'Meeting',
'start' => strtotime('2014-09-09'),
'color' => '#CC0000',
'allDay' => true,
'url' => 'http://anyurl.com'
);
$items[] = array(
'title' => 'Meeting reminder',
'start' => '2014-09-15 05:20:17',
'end' => '2014-09-15 05:30:17',
'color' => 'blue',
);
echo CJSON::encode($items);
Yii::app()->end();
And another issue i have is when enable true as below, it says
'editable'=>'true',
'selectable' => true,
Property "EFullCalendar.editable" is not defined.
Property "EFullCalendar.selectable" is not defined.
Here is how it should work exactly, http://fullcalendar.io/js/fullcalendar-2.1.1/demos/external-dragging.html
If all events are being displayed as All Day, make sure that you don't have allDayDefault set to true (take a look at the docs).
For your second issue, make sure editable is true (boolean instead of string). If it still doesn't work, please include the javascript where you set the default options for fullCalendar.
I try use callback. If data success update then i need to display modal window. But its not working! Help please! I dont know, how it works. Write me please.
In View
<?php
$this->widget('editable.EditableField', array(
'type' => 'select',
'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
'model' => $model,
'attribute' => 'category_id',
'url' => $this->createUrl('course/updateSameInfo'),
'source' => Editable::source(Coursecat::model()->findAll(), 'id', 'name'),
'placement' => 'right',
));
?>
In Controller
public function actionUpdateSameInfo()
{
$es = new EditableSaver('Course'); //'User' is name of model to be updated
$es->update();
}
Use success property. Here is the documentation http://x-editable.demopage.ru/index.php?r=site/widgets#Options
Try this
<?php
$this->widget('editable.EditableField', array(
'type' => 'select',
'params' => array('YII_CSRF_TOKEN' => Yii::app()->request->csrfToken),
'model' => $model,
'attribute' => 'category_id',
'url' => $this->createUrl('course/updateSameInfo'),
'source' => Editable::source(Coursecat::model()->findAll(), 'id', 'name'),
'placement' => 'right',
'success' => 'js: function(response, newValue) {
console.log(response); //Open the browser console to check the data
}'
));
?>
I'm trying to give several parameters in a remote_function like this:
<?php
echo remote_function(array( 'update' => 'test',
'url' => 'conges/verifdate',
'with' => "'date_deb=' + $('date_debut').value"
));
?>
This code works (in my action.class I can get the parameter).
But when I try to give a second parameter, it doesn't work:
<?php
echo remote_function(array( 'update' => 'test',
'url' => 'conges/verifdate',
'with' => "'date_deb=' + $('date_debut').value"."'+&date_fin=' + $('date_fin')"
))
?>
What am I doing wrong?
I did it like this:
'url' => 'conges/verifdate?vars=serialize(array("var1" => 1, "var2" => 2))'
In your remote action you do:
$vars = unserialize($request->getParameter('vars'));