I am trying to append text to CJuiDialog widget in Js code, In CJuiDialog content i have two buttons ,
Dialog Widget code,
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'update_tasks',
'options'=>array(
'title'=>'Create Tasks',
'autoOpen'=>false,
'modal'=>false,
'width'=>500,
'height'=>300,
),
));
?>
<table cellspacing="20">
<tr>
<td><?php echo CHtml::button('Add to Current Pending Tasks',array('id'=>'AddPendingTasks'));?></td><td style = "width : 20px"></td>
<td><?php echo CHtml::button('Add to Tasks',array('id'=>'AddTasks'));?></td>
</tr>
</table>
<?php $this->endWidget();?>
Am opening this dialog inside JS code on another button action,
$('.updatetask_btn').click(function(){
var filterid = $(this).closest('tr').find('select')[0].options[$(this).closest('tr').find('select')[0].selectedIndex].value;
var filtername = $(this).closest('tr').find('select')[0].options[$(this).closest('tr').find('select')[0].selectedIndex].text;
document.getElementById('filter-id').value = filterid;
var div = document.getElementById('update_tasks');
div.innerHTML = '<label><b>'+$('#camp-name').val()+' - '+filtername+'</b></label><br>'+div.innerHTML ;
//----- Here am appending text to the dialog dynamically ---
$('#update_tasks').dialog('open');
});
Appending text blocks the two button actions in CjuiDialog content . both button onclick action not working when i append text here. Please give me any idea.
Actually I didn't fully understood your needs but I always do this way:
You need to understand and adapt to your needs.
In main view
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
Yii::app()->clientScript->scriptMap['jquery-ui.js'] = false;
Yii::app()->clientScript->scriptMap['jquery-ui.min.js'] = false;
....
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id'=>'addot-dialog',
'options'=>array(
'title' => 'Aggiungi OT',
'autoOpen' => false,
'width' => 600,
'height' => 'auto',
'closeOnEscape' => true,
// 'close' => 'js:function() { $("table.items").find("tbody tr div.log-active").removeClass("log-active").addClass("log-inactive"); }'
)
));
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
.....
$loadurlvendita = Yii::app()->createUrl("/otpos/otVendita/",
array("idot" => $this->idot, "codfis" => $this->codfis));
....
on click here I open and fill let dialog with .load() from another view with render partial
CHtml::link('','',
array('class'=>'be-icon vendita','style'=>'display:block;float:right;padding-right:6px;',
'onClick'=>'$("#venditaot-'.$this->idot.'").dialog("open").load(\''.$loadurlvendita.'\');'
)).
controller
public function actionOtVendita($idot, $codfis) {
$proprietari = Otpos::model()->getOtposProprietari($idot);
$this->renderPartial('vendita', array('idot' => $idot, 'codfis' => $codfis, 'proprietari' => $proprietari), false, true);
}
I hoe it'll help in some way other wise clear better your needs.
Related
I have theese three acf_form. I want to show these form one by one as well as I want to save every form on button click through ajax without page refresh. Right now it's refreshing page whenever I update.
I will show through display none & block using js.
<div class="SetupNew">
<h2>Setup Deals To Attract New Clientele</h2>
<p>Example: buy $15 get $30 for services</p>
<p id="newDealsTxt">[Click Here To Setup] </p></div>
<?php acf_form($args = array(
'post_id' => $post_id,
'field_groups' => array(2029),
'form_attributes' => array(
'id'=>'newDeals'
),
)); ?>
<div class="SetupEx">
<h2>Setup Deals To Bring In Clientele During Nonpeak Hours</h2>
<p>Example: buy $15 get $30 for services Tue-Thur 9am - 2pm.</p>
<p id="exDealsTxt">[Click Here To Setup]</p></div>
<?php acf_form($args = array(
'post_id' => $post_id,
'field_groups' => array(2047),
'form_attributes' => array(
'id'=>'exDeals'
),
)); ?>
<div class="SetupFb">
<h2>Setup $5 Off Coupon To Increase Testimonials And Sharing</h2>
<p>Example: Leave a testimonial and get $5 off your next service.</p>
<p id="fbDealsTxt">[Click Here To Setup] </p></div>
<?php acf_form($args = array(
'post_id' => $post_id,
'field_groups' => array(2123),
'form_attributes' => array(
'id'=>'fbDeals'
),
)); ?>
<h2 id="backk">Back << </h2>
This comes pretty late, but I had the same problem today. For reference, here's my javascript:
// call this function on document ready or when your ajax page is loaded
function renderPage() {
// initialize the acf script
acf.do_action('ready', $('body'));
// will be used to check if a form submit is for validation or for saving
let isValidating = false;
acf.add_action('validation_begin', () => {
isValidating = true;
});
acf.add_action('submit', ($form) => {
isValidating = false;
});
$('.acf-form').on('submit', (e) => {
let $form = $(e.target);
e.preventDefault();
// if we are not validating, save the form data with our custom code.
if( !isValidating ) {
// lock the form
acf.validation.toggle( $form, 'lock' );
$.ajax({
url: window.location.href,
method: 'post',
data: $form.serialize(),
success: () => {
// unlock the form
acf.validation.toggle( $form, 'unlock' );
}
});
}
});
}
I'm trying my best to alter the below code so that it produces a popup box with a warning and asking for confirmation.
echo CHtml::ajaxButton(Yii::t('mc', 'Wipe Server'), '', array(
'type'=>'POST', 'data'=>array('ajax'=>'wipe', Yii::app()->request->csrfTokenName=>Yii::app()->request->csrfToken,),
'success'=>'function(e) {if (e) alert(e);}'
),
I expect adding 'confirm' => 'Wipe your server?' to add a dialog box but I'm not having much success.
I have this in ServerController:
case 'wipe':
if (Yii::app()->user->can($id, 'wipe'))
{
if (!McBridge::get()->serverCmd($id, 'run:builtin:script wipe'))
echo McBridge::get()->lastError();
}
break;
I would be grateful if anyone can point out where I am going wrong or generally point me in the right direction.
Thank you
Try this one
In Yii ajax button, beforesend function is there. Use that.
Example
<?php
echo CHtml::ajaxButton(
'Submit',
array('controlleraction'),
array(
'success' => 'js:
function (data){
}
',
'type' => 'POST',
'beforeSend' => 'js:
function(){
var r = confirm("Are you sure?");
if(!r){return false;}
}
',
));
?>
I want to change pagesize of listview using dropdown. please help me to find solution.
I have read many article but not able to do this. can u find where I'm making mistake
I'm using following code.
code for index.php (view)
code for dropdownlist
<?php echo CHtml::beginForm(); ?>
<?php echo CHtml::dropDownList('CategoryMst_pagesize','20',
array('10'=>'10','20'=>'20','50'=>'50','100'=>'100'
),
array('class'=>'form-control',
/*'ajax'=>array(
'type'=>'GET',
'data'=>array('pagesize'=>'js:this.value'),
'ajaxUpdate':()
),*/
));
?>
<?php echo CHtml::endForm(); ?>
code for listview
<?php $this->widget('zii.widgets.CListView',array(
'id'=>'category_list',
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
'summaryText'=>'{start} - {end} of {count} results',
));
?>
<?php
Yii::app()->clientScript->registerScript('category_update',
"$('#CategoryMst_pagesize').change(function(){
$.fn.yiiListView.update('category_list', {
data: $(this).serialize(),
}
);
});
return false;",
CClientScript::POS_READY);
?>
code in cotroller
public function actionIndex($pagesize=20)
{
$dataProvider=new CActiveDataProvider('CategoryMst',array(
'criteria'=>array(
),
'pagination'=>array(
'pageSize'=>$pagesize,
),
));
$this->render('index',array('dataProvider'=>$dataProvider));
}
You really should not be using $('#CategoryMst_pagesize').change use https://api.jquery.com/on/ instead.
Then from what I see you are not remembering the page size anywhere, after you change it 1 time, as soon as you go to another page it will revert back to what you had before. THis is how I do it:
1) First use something to remember the page size, because right now you do not. I personally recommend this one http://www.yiiframework.com/extension/esaverelatedbehavior/ as it is really, really, really good. It also remember your filters (priceless).
2) create a function for your controller that will just save the page size.
/**
* Saves the new page size for this particular model
*/
public function actionPageSize($pagesize)
{
\Yii::app()->user->setState($this->modelName() . '_pagesize', $pagesize);
}
3) create the dropdown for the pagesize, I use Select 2 but you can use a normal dropdown. same Idea
<?php $this->widget('MySelect2', array(
'name' => 'pageSize',
'data'=>array('10' => '10', '25' => '25', '50' => '50', '100' => '100'),
'options'=>array('allowClear' => false, 'minimumResultsForSearch' => 30),
'htmlOptions' => array(
'data-ajax-dropdown' => $this->createUrl('pageSize'),
'style' => 'width: 80px',
'options'=>array(
(Yii::app()->user->getState($this->modelName() . '_pagesize', Yii::app()->params['defaultPageSize']))=>array('selected'=>'selected')
))));?>
4) I autosubmit the dropdowns for the page size like you do, but I submit them to the function above not to the index page
/*==========================
AUTOSUBMIT DROPDOWNS FOR THE PAGE SIZE
==========================*/
$('#pageSize').live('change',function(e){
var element = $(this);
jQuery.ajax({
"type": "GET",
"url": $(this).attr("data-ajax-dropdown"),
"cache": false,
"data":{pagesize: $(this).val()}
})
.success(function ( response ) {
$.fn.yiiGridView.update(element.closest('.widget.table').find('div.grid-view').attr('id'));
$.jGrowl("Pagination changed", { life: 2000 });
});
});
PS: I know I should not use .live
5) In the search for the model just like you do I have
return new \CActiveDataProvider($this, array(
'criteria'=>$criteria,
'sort'=>array(
'defaultOrder'=>$this->getTableAlias(false,false) . '.name asc',
),
'pagination'=>array(
'pageSize'=> \Yii::app()->user->getState(get_class($this) . '_pagesize', \Yii::app()->params['defaultPageSize']),
),
));
I have a Yii dropdownlist and text field, when i select the dropdown list item, this name should be displayed in textfield. I tried this concept using ajax with But it updates after page refresh only.I have pasted my code here, please look-through and suggest me how to set
textfield after every immediate selection of drop down listed item.
The following code resides protected/views/form
<td>
<?php echo $form->labelEx( ScriptQuestion::model(),'Field'); ?></td><td>
<?php echo CHtml::activedropDownList( ScriptQuestion::model(),'crm_base_contact_form_field_id',$select_field,
array(
'id' => 'send_bcfield',
'class' => 'col_165',
'ajax' => array(
'type' => 'POST',
'url' => CController::createUrl('DisplayMessage'),
'update' => '#question_editor',
'data' => array('bcfield' => 'js:this.value'),
'success'=> 'function(data) {$("#question_editor").empty();
$("#question_editor").val(data);
} ',
))
); ?>
</td>
<td>
<?php echo $form->textArea($model, 'message', array('id'=>'question_editor','maxlength'=>508, )); ?>
</td>
This is controller action:
public function actionDisplayMessage(){
$q = $_POST['bcfield'];
$model=ScriptQuestion::model()->findAll();
$sql = "SELECT name FROM crm_field WHERE crm_field_id=". $q ;
$command = Yii::app()->db->createCommand($sql);
$result= $command->queryScalar();
echo "%".$result."%";
$this->performAjaxValidation($model);
}
No need to Ajax, it's just a simple javascript/jQuery .
Just do this ( replace editor1 with your ckeditor instance name) :
<script>
$("#send_bcfield").change(function(){
var selected = $("#send_bcfield option:selected").val();
CKEDITOR.instances.editor1.setData(selected);
});
</script>
Or change your code to this :
<?php
echo CHtml::activedropDownList(ScriptQuestion::model(), 'crm_base_contact_form_field_id', $select_field, array(
'id' => 'send_bcfield',
'class' => 'col_165',
'onchange' => '$("#send_bcfield").change(function(){
var selected = $("#send_bcfield option:selected").val();
CKEDITOR.instances.editor1.setData(selected);
});',
)
);
?>
Update : I changed my code to changing a ckeditor value according to your comment below my answer.
probably you simply need to add this to CHtml::activedropDownList settings:
'onchange' => "$('question_editor').val($('#send_bcfield option:selected').text())"
I'm building a website with Yii framework 1.1 and i'm implementing a portion wherein i have a like button associated with each post.i want to update the content of the like buttons text everytime i click on it without refreshing the page?please help?
EDIT
i did this
`id;
$foo = $data->likes;
echo CHtml::ajaxbutton($foo.' '.'Likes',
array('post/like/'.$id),
array(
'type'=>'POST',
'success'=>'js:function(data){ $.fn.yiiAjaxButton.update("label");}')
);
?>`
still doesnt work
Your View should be like bellow
<?php
$postId = 1; //Your post id
echo CHtml::Button('SUBMIT', array('onclick' => 'getComments(this);', 'data-value' => $postId, 'value' => 'Get Comments'));
?>
And Write your Ajax call some thing like
<script type="text/javascript">
function getComments(obj)
{
$PostID = $(obj).data('value');
$.get('Controller/YourMethod', {id:$PostID}, function(dataJSON)
{
//Get data in JSON formate
},'JSON');
}
</script>
EDIT
If you want to add Ajax call directly to your button, you can do as
<?php
$postId = 1;
echo CHtml::Button('SUBMIT', array('value' => 'Get Comments','onclick' => ''
. '$.get("Controller/YourMethod", {id:'.$postId.'}, function(dataJSON)
{
//Do what ever you want here
},"JSON");'));
?>