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
}'
));
?>
Related
I use the yii2 kartik switch input with the type radio and i want to get the value of the selected option in javascript (specially in a JsExpression), here is my code :
$model->orientation = 'Portrait';
echo $form->field($model, 'orientation')->widget(SwitchInput::classname(), [
'name' => 'information_orientation',
'type' => SwitchInput::RADIO,
'value' => 'Portrait',
'items' => [
['label' => 'Portrait   ', 'value' => 'Portrait'],
['label' => 'Paysage   ', 'value' => 'Paysage'],
],
'pluginOptions' => [
'onText' => 'Oui',
'offText' => 'Non',
'onColor' => 'success',
'offColor' => 'danger',
'size' => 'mini'
],
'labelOptions' => ['style' => 'font-size: 13px'],
]);
I have tried :
$([name='information-orientation']).val()
But it returned an undifined value
SwitchInput class does not care about the name property you give it
according to their docs, you need to wrap name in a options array
echo $form->field($model, 'orientation')
->widget(SwitchInput::classname(), [
'options' => ['name' => 'information_orientation'],
'type' => SwitchInput::RADIO,
....
from docs:
options: array the HTML attributes for the widget input tag.
edit:
you can then use the following
// to get value:
$("[name='information_orientation']").val()
// to check if the switch is or on off
$("[name='information_orientation']").prop('checked')
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.
How to draw a CGridView after document ready? I have Yii framework 1.14, jquery and jquery.ui successfully loaded!
Console.error! Because the grid is draw after document ready
TypeError: jQuery(...).dialog is not a function
jQuery("#dialog").dialog();
My code:
[
'class' => 'zii.widgets.grid.CButtonColumn',
'template' => '{edit}',
'headerHtmlOptions' => ['class' => 'col-lg-1', 'style' => 'text-align:center'],
'buttons' => [
'edit' => [
'label' => '<span class="glyphicon glyphicon-comment"></span>',
'url' => "Yii::app()->controller->createUrl('ViewComments',['key'=>\$data->key])",
'imageUrl' => null,
'options' => [
'style' => 'color: black',
'rel' => 'tooltip',
'data-toggle' => 'modal',
'data-target' => "#myModal",
'title' => 'Комментировать',
'ajax' => [
'type' => 'post',
'url' => 'js:$(this).attr("href")',
'dataType' => 'html',
'success' => 'js:function(data){
jQuery("#dialog").dialog();
}'
],
],
],
]
],
Have you tried reloading js in your view
Yii::app()->clientScript->registerCoreScript('jquery');
Yii::app()->clientScript->registerCoreScript('jquery.ui');
As you probably know, Yii does not perform client-side validation with CHtml::ajaxSubmitButton. So after a long time spending on google and stackoverflow, I found that I should use the following link
a-simple-way-to-get-yii-client-side-form-validation-run-when-submitting-by-ajax
Now, It can perform client-side validation. But, the success or complete ajax functions does not fire after validation.
Any Idea?
To be more familiar with topic, I put my codes here:
Yii::app()->clientScript->registerCoreScript('yii');
Yii::app()->clientScript->registerScript('Yii Fix',";$.yii.fix = {
ajaxSubmit : {
beforeSend : function(form) {
return function(xhr,opt) {
form = $(form);
$._data(form[0], 'events').submit[0].handler();
var he = form.data('hasError');
form.removeData('hasError');
return he===false;
}
},
afterValidate : function(form, data, hasError) {
$(form).data('hasError', hasError);
return true;
}
}
};",CclientScript::POS_HEAD);
My form:
$uniqid = uniqid();
$form = $this->beginWidget('CActiveForm', array(
'id' => 'pagescontents-add-new-contents'.$uniqid,
'htmlOptions' => array(
'class' => 'form-horizontal',
'role' => 'form'
),
'enableClientValidation' => true,
'enableAjaxValidation'=>true,
'clientOptions' => array(
'validateOnSubmit' => true,
'validateOnChange'=>false,
'afterValidate'=>'js:$.yii.fix.ajaxSubmit.afterValidate',
),
));
//The rest of code
...
//Ajax submit button
$button_uniqid = uniqid();
echo CHtml::ajaxSubmitButton(Messages::getMessage('ADD_NEW'), $this->createUrl('pagescontents/addPage/'), array(
'beforeSend' => '$.yii.fix.ajaxSubmit.beforeSend("#pagescontents-add-new-contents'.$uniqid.'")',
'type'=>'POST',
'success' => "js:function(data){
$('#page_modal').html('');
$('.modal-backdrop').remove();
$('#pageContents_list').html(data);
}",
),
array(
'class' => 'btn btn-primary',
// 'data-dismiss' => 'modal',
'id' => 'deletesubmit_' . $button_uniqid
)
);
I try your code and find that if you remove the line "'enableAjaxValidation'=>true," your code will work perfectly please check it and let me know that is work for you too or not.
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.