Ajaxsubmitbutton Not Passing ID - javascript

I have a problem using bootstrap modal for updating data.
On CGridView selectionChanged, it will trigger a function to show modal dialog form and insert the data to the form
Here is my CGridView :
<?php
$this->widget('customCGridView', array(
'id'=>'contactperson-grid',
'itemsCssClass' => 'table table-bordered',
'selectionChanged'=>'showmodal',
'dataProvider' => $contactperson->search(),
'emptyText' => '',
'enableSorting' => false,
'htmlOptions' => array('class' => ' '),
'columns' => array('nama', 'jabatan')
));
?>
On selectionChanged, it will trigger this script to open the update dialog modal and fill the form with selected CGridView column data :
function showmodal(grid_id) {
var keyId = $.fn.yiiGridView.getSelection(grid_id);
keyId = keyId[0]; //above function returns an array with single item, so get the value of the first item
$.ajax({
url: '<?php echo $this->createUrl("suppliertable/personview"); ?>',
data: {id: keyId},
type: 'GET',
success: function(data) {
$("#contact-person-modal").html(data);
$('#kontakmodalupdate').modal('show');
}
});
}
Here is the actionPersonView which will be executed upon selecting column :
public function actionPersonView($id) {
$contactperson = SupplierContactPersonTable::model()->findByPk($id);
if ($contactperson === null)
throw new CHttpException(404, 'The requested page does not exist.');
$this->renderPartial('updateForm', array('contactperson'=> $contactperson));
Yii::app()->end();
}
Now, here is the problem :
When I Click update button on update form, I need to pass ID to my action :
public function actionPersonUpdate($id) {
$model2=$this->loadModel2($id);
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
if(isset($_POST['SupplierContactPersonTable']))
{
if($model2 === null) {
throw new CHttpException(404, 'The requested page does not exist.');
}
$model2->attributes=$_POST['SupplierContactPersonTable'];
$model2->save();
}
}
To pass this value, I'm using AjaxButton on my form:
<div id="contact-person-modal">
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'suppliercontactmodalform',
'htmlOptions' => array(
'class' => 'smart-form',
'novalidate' => '1',),
'enableAjaxValidation' => false,));
?>
...
<footer>
<button type="button" class="btn btn-labeled btn-danger cancel-button" style="float: left">
Hapus Pengguna
</button>
<?php
echo CHtml::ajaxButton('Update', Yii::app()->createUrl('suppliertable/personupdate',array('id'=>$contactperson->contact_person_id)), array('type'=>'POST'), array('type'=>'submit',"class" => "btn btn-primary"));
?>
<button type="button" class="btn btn-default" data-dismiss="modal">
Batal
</button>
</footer>
...
However, it seems like ID isn't passed. Here is Firebug console :
POST http://localhost/webapp/index.php/suppliertable/personupdate/
400 Bad Request
As you can see, no ID is passed.
But, if I use static parameter value :
echo CHtml::ajaxButton('Update', Yii::app()->createUrl('suppliertable/personupdate',array('id'=>'5')), array('type'=>'POST'), array('type'=>'submit',"class" => "btn btn-primary"));
The ID is passed :
POST http://localhost/webapp/index.php/suppliertable/personupdate/5
So, I think the problem is here, is not outputing value :
$contactperson->contact_person_id
Here is generated jQuery from Yii :
jQuery('body').on('click','#yt0',function({
jQuery.ajax({
'type':'POST',
'url':'/webapp/index.php/suppliertable/personupdate id=',
'cache':false,
'data':jQuery(this).parents("form").serialize()
});
return false;
});
Thanks for your help :)

I've found my solution.
In case someone have the same problem, I need to update my actionPersonView method :
public function actionPersonView($id) {
if (Yii::app()->request->isAjaxRequest) {
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
$contactperson = SupplierContactPersonTable::model()->findByPk($id);
if ($contactperson === null)
throw new CHttpException(404, 'The requested page does not exist.');
$this->renderPartial('updateForm', array('contactperson'=> $contactperson),false,true);
Yii::app()->end();
}
}
I need to add in my actionPersonView method
$this->renderPartial('updateForm', array('contactperson'=> $contactperson),false,true);
And add
Yii::app()->clientScript->scriptMap['jquery.js'] = false;
Yii::app()->clientScript->scriptMap['jquery.min.js'] = false;
To prevent the script being executed multiple.

Related

Add temporary active class

I have a method for adding likes to a page
blade.php
<a href="/article/{{ $article->id }}?type=heart" class="comments-sub-header__item like-button">
<div class="comments-sub-header__item-icon-count">
{{ $article->like_heart }}
</div>
<a href="/article/{{ $article->id }}?type=finger" class="comments-sub-header__item like-button">
<div class="comments-sub-header__item-icon-count">
{{ $article->like_finger }}
</div>
Adding a like on click
js
$(function() {
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content'),
},
});
$('.like-button').on('click', function(event) {
event.preventDefault();
let href = $(this).attr('href');
$.ajax({
url: href,
type: 'POST',
success: function() {
window.location.reload();
},
});
});
});
Next, I made an active class with styles, and when I click on the like to the class class="comments-sub-header__item like-button" this class should be added active
But there is one more thing, my likes are stored in cookies, and 24 hours after clicking we can put a new like, that is, the active class should also be disabled after 24 hours
This is how I implemented it adding a like to cookies
Route::post('article/{id}', 'App\Http\Controllers\ArticleController#postLike');
public function postLike($id, Request $request) {
$article = Article::find($id);
if(!$article){
return abort(404);
}
$type = $request->input('type');
if ($article->hasLikedToday($type)) {
return response()
->json([
'message' => 'You have already liked the Article '.$article->id.' with '.$type.'.',
]);
}
$cookie = $article->setLikeCookie($type);
$article->increment("like_{$type}");
return response()
->json([
'message' => 'Liked the Article '.$article->id.' with '.$type.'.',
'cookie_json' => $cookie->getValue(),
])
->withCookie($cookie);
}
public function hasLikedToday(string $type)
{
$articleLikesJson = Cookie::get('article_likes', '{}');
$articleLikes = json_decode($articleLikesJson, true);
if (!array_key_exists($this->id, $articleLikes)) {
return false;
}
if (!array_key_exists($type, $articleLikes[$this->id])) {
return false;
}
$likeDatetime = Carbon::createFromFormat('Y-m-d H:i:s', $articleLikes[$this->id][$type]);
return ! $likeDatetime->addDay()->lt(now());
}
public function setLikeCookie(string $type)
{
$articleLikesJson = Cookie::get('article_likes', '[]');
$articleLikes = json_decode($articleLikesJson, true);
$articleLikes[$this->id][$type] = now()->format('Y-m-d H:i:s');
$articleLikesJson = json_encode($articleLikes);
return cookie()->forever('article_likes', $articleLikesJson);
}
As I understand it, all this should be done in js, but I still do not really understand it, so I ask for a hint
Simply share a variable in the view where you show the "like" buttons somewhere in your controller:
// Your controller
public function show(Request $request, $postId)
{
$post = Post::find($postId);
$hasLikedToday = $post->hasLikedToday('heart');
return view('your.view.file', [
'article' => $article,
'hasLikedToday' => $hasLikedToday, // share this variable to check if you've liked today
]);
}
After sending the hasLikedToday variable to your blade where the like buttons are defined, you simply check if the variable is true, if so, show the active class. Now every time you refresh that page, it will check if the active class must be shown, no need for javascript to do that.
<a href="/article/{{ $article->id }}?type=heart" class=" ... {{ $hasLikedToday ? 'active' : '' }}">
<div class="comments-sub-header__item-icon-count">
{{ $article->like_heart }}
</div>

Laravel & JQuery: Display mysql row data if ID is set

I have manage to get autocomplete data with typeahead search tutorial where I change in a way that now searching by three columns instead of one. So, when I start typing in search field autocomplete display:
Street from-to
and based on that I supposed to display other data from that ID (ID of that row but ID is not displayed).
You can see how it looks in my controller:
public function ajaxData(Request $request)
{
$query = $request->get('query', '');
$streets = Street::select('id', 'name')
->where('name', 'LIKE', '%'.$query.'%')
->get();
$results = array();
foreach($streets as $sn) {
$street_numbers = StreetNumber::select('from', 'to')
->where('town_id', Auth::user()->town_id)
->where('street_id', $sn->id)
->get();
foreach($street_numbers as $st) {
$data = array(
'name' => $sn->name." ".$st->from."-".$st->to
);
$results[] = $data;
}
}
return response()->json($results);
}
In view I supposed to select from autocomplete and when I click on submit it should display data like town, settlement etc...
But, if I try to use $street_numbers variable it shows me error:
(2/2) ErrorException
Undefined variable: street_numbers
In view beside field I have JQuery from typeahed tutorial:
{!! Form::open(['route'=>'add.index', 'method'=>'GET']) !!}
<div class="col-sm-12">
<div class="panel panel-default">
<div class="panel-heading">Search</div>
<div class="panel-body">
<div class="input-group">
{!! Form::text('search_text', null, array('placeholder' => 'Street from - to','class' => 'form-control','id'=>'search_text')) !!}
<span class="input-group-btn">
{!! Form::button('<i class="fa fa-search"></i>', ['type' => 'submit', 'class'=>'btn btn-default']) !!}
</span>
</div>
</div>
</div>
</div>
{!! Form::close() !!}
<script type="text/javascript">
var url = "{{ route('autocomplete.ajax') }}";
$('#search_text').typeahead({
source: function (query, process) {
return $.get(url, { query: query }, function (data) {
return process(data);
});
}
});
</script>
I'm very stuck on this one and don't know how to start from here because in JS or JQuery I'm a beginner.
Before ajaxData() function I have index() function and there I have:
return view('members.index', compact('towns', 'user', 'activist', 'capillary'));
So there is my view.
I'm trying to use $street_numbers variable in view like this:
<div class="col-sm-6">
<div class="form-group">
{!! Form::label('', 'Settlement') !!}
{!! Form::select('', [$street_numbers? $street_numbers->settlement->name : null => $street_numbers? $street_numbers->settlement->name : null], null, ['class'=>'form-control', 'readonly']) !!}
</div>
</div>
I succeeded and I want to share with others in case somebody needs it:
In submit button I placed 'id'=>'get_cust_data' and then I made separate .js file where I pull information from autocomplete search field when it's submitted.
JS:
$(document).ready(function(){
$('#get_cust_data').click(function(){
var st = $.trim($("#search_text").val());
get_cust_data(st);
});
});
In controller I get data with explode function because, as I said in first post I have street-from-to from database, not just one data. In further codes you will see how I get ID from street and then object which I use to get other info from same row like settlement, electorUnit and so...
public function get_cust_data(Request $reques)
{
$arr = explode("-", $reques->st);
$street = $arr[0];
$from = $arr[1];
$to = $arr[2];
// Street ID
$street_id = Street::select('id')
->where('name', $street)
->first()->id;
// Object
$street_data = StreetNumber::select('*')
->where('street_id',$street_id)
->where('from', $from)
->where('to', $to)
->get();
$result = array();
// Settlement ID
$settlement_id = $street_data[0]->settlement_id;
$result['settlement_id'] = $settlement_id;
// Settlement Name
$settl_data = Settlement::select('name')
->where('id',$settlement_id)
->get();
// ElectoralUnit ID
$electoral_unit_id = $street_data[0]->electoral_unit_id;
$result['electoral_unit_id'] = $electoral_unit_id;
// ElectoralUnit Name
$el_unit_data = ElectoralUnit::select('name')
->where('id',$electoral_unit_id)
->get();
// ElectoralUnitNumber
$el_unit_number_data = ElectoralUnit::select('electoral_unit_number')
->where('id',$electoral_unit_id)
->get();
$result['s_name'] = $settl_data[0]->name;
$result['e_name'] = $el_unit_data[0]->name;
$result['e_n_name'] = $el_unit_number_data[0]->electoral_unit_number;
$result['street'] = $street;
$result['str_id'] = $street_id;
return response()->json(json_encode($result));
}
Then in the sam JS file, which is connected in header to view, I put another function that I googled and can't explain completely how it works, but that function forwarding variables from controller through view with fields ID-s like this:
function get_cust_data(street_data){
var method_url= "/get_cust_data";
$.ajax({
type: "POST",
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: method_url,
cache: false,
data:{ st:street_data},
async: true,
success: function(response){
var data = JSON.parse(response);
// console.log(data.id);
$('#street').append("<option value='"+data.street+"'>"+data.street+"</option>");
$('#settlement_id').append("<option value="+data.settlement_id+">"+data.s_name+"</option>");
$('#electoral_unit').append("<option value='"+data.e_name+"'>"+data.e_name+"</option>");
$('#electoral_unit_number').append("<option value="+data.electoral_unit_id+">"+data.e_n_name+"</option>");
// console.log(data.message);
}, error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
I hope that at least I explained a bit and will help somebody. Cheers!

How to use ajax to change status whenever I click in cakephp

I want to also change my status message when I click on them. This is the image where I want to apply
As shown in image, the active status need to change to inactive when I click on it. I can do it with edit page but now I want to change status when I click on active on page load. this is my code ctp file
<td class="center">
<?php if($listings['status']=="1") { ?>
<span class="label label-success">Active</span>
<?php } else if($listings['status']=="0") {?>
<span class="label label-error">Inactive</span>
<?php } ?>
</td>
this is controller code
if ((!empty($this->request->data['action'])) && (!empty($this->request->data['ids'])))
{
$action=$this->request->data['action'];
$ids=$this->request->data['ids'];
switch($action)
{
case "active":
$this->request->data['status']="1";
foreach($ids as $id)
{
$this->Listing->id = $id;
$this->Listing->save($this->request->data);
}
$this->Session->setFlash(__('Active Successfully'),'default',array('class' => 'alert alert-success'), 'alert');
$this->redirect(array('controller'=>'Listing','action' => 'index'));
break;
case "inactive":
$this->request->data['status']="0";
foreach($ids as $id)
{
$this->Listing->id = $id;
$this->Listing->save($this->request->data);
}
$this->Session->setFlash(__('InActive Successfully!'),'default',array('class' => 'alert alert-success'), 'alert');
$this->redirect(array('controller'=>'Listing','action' => 'index'));
break;
Please help me and tell how to do that with ajax or jquery.
Try this:
HTML: <button type="button" class="active" data-id="2">Active/button>
//Note that data-id ...It's just an attribute I created, and the value "2" I //believe will be dynamic in your case -Probably that college ID in the DB
JAVASCRIPT (Jquery required)
<script>
$(document).on('click', 'button[data-id]', function(event) {
event.preventDefault();
var collegeID = $(this).attr('data-id');
$.ajax({
url: 'changeStatus',
type: 'POST',
dataType: 'json',
data: {id: collegeID},
success: function(data){
if (data['status'] == "success") {
$('button[data-id]').removeClass('active').addClass('inactive');
/*Class active and inactive should be in your CSS with color according to their names*/
};
}
});
});
</script>
CONTROLLER:
public function changeStatus(){
$this->autoRender = false;
if ($this->request->is('ajax')) {
$data = $this->request->data;
/*The id that was passed thru data-id attribute is here: */
//$data['id'] Use it to update your DB
//After successful update
$response = array('status' => 'success');
return json_encode($response);
}
}
Then Last but not the least, is your route:
Router::connect('/changeStatus', array('controller' => 'yourcontroller', 'action' => 'changeStatus'));
Hope that help.
Good luck
You can actually do as simple as this:
$("body").on("click", "#status", function(e) {
e.preventDefault();
var stat = find("span#span_id").val(); // get the status current value
$.get('./db_file', function(data) {
if (data.stat != stat)
$("#span_id").removeClass("label label-error").addClass("label label-success");
}, "json");
});
Something like that would work.

Where to put the modal layout and how to fill it with dynamic content

I have got the following question.
I have got an application built in ZF2. In some pages I have got a grid with some tabular info. Each line has got a button which should open a bootstrap modal and populate it with dynamic forms and data.
Now here is my question. I want to have a plain modal with no content available everywhere and fill it with dynamic content. I don't want to define my base modal everywhere.
I have seen some information in this link Zend Framework 2 & jquery modal dialog but it doesn't totally answer my question because where do I put the basic modal layout?
The way i do it is. on the ZF2 default layout i have the modal i want to load with dynamic data, i have set a variable for the title of the modal and a variable for the content. I use it to provide a message to the users when they save data to db successfully or if that fails. So inside my controller action when the page loads i create a session of that message and sent it to the layout see below example:
$t_session = new Container('msg');
$t_session->msg = 'Access Denied...';//body
$t->msgheader = 'Warning!';//title
return $this->redirect()->toRoute('users', array());
when the redirect happens to the users route
//seesion modal for access denied
$mysession="";
$t_session = new Container('msg');
$mysession = $t_session->msg;
unset($t_session->msg);
$this->layout()->mysession = $mysession;
if(isset($t_session->msgheader)){
$mysessiontitle = $t_session->msgheader;
unset($t_session->msgheader);
$this->layout()->mysessiontitle = $mysessiontitle;
}
as you see above i pass that session message to the default layout with
$this->layout()->mysession = $mysession;
and to load the modal i use this code.
<?php if($this->mysession != ''){?>
<script>
$(window).load(function() {
$('#idofmodaltoload').modal('show');
});
</script>
<?php } ?>
So if the body msg of modal is passed from some action to the layout thus not being empty i use JQuery to load that modal. I hope this helps.
I use a combination of a view helper and a partial - Although my 'dynamic content' is 99% of the time a form.
The view helper:
class Modal extends AbstractHelper
{
protected $template = 'base-module/widget/modal';
public function getTemplate()
{
return $this->template;
}
public function setTemplate($template)
{
$this->template = $template;
}
public function setOption($name, $value)
{
switch($name) {
case 'template' :
$this->setTemplate($value);
break;
default :
parent::setOption($name, $value);
}
}
public function __invoke($title = null, $content, $target)
{
if (null !== $title) {
return $this->render($title, $content, $target);
}
return $this;
}
public function render($title, $content, $target)
{
$partial = $this->getPlugin('partial');
return $partial($this->template, array(
'title' => $title,
'content' => $content,
'target' => $target
));
}
}
The modal's default markup is set with the view script path $template
<div class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<?php if (! empty($this->title)) : ?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title"><?php echo $this->title; ?></h4>
</div>
<?php endif; ?>
<div class="modal-body" data-action="<?php echo $target; ?>">
<?php echo $this->content; ?>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default modal-close" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary modal-submit">Save changes</button>
</div>
</div>
</div>
</div>
Notice the variables here; $title, $content and $action. The $action is the URL that the modal will submit to when the 'save changes' button is clicked.
The JS looks like this
$(document).on('click', '.load-modal', function(event) {
event.preventDefault();
var $this = $(this),
$container = $($this.data('container')),
target = $this.data('target');
if (! target) target = $this.attr('href');
if (! target) return;
var isXmlHttpRequest = true;
var ajax = $.ajax({
type : 'get',
url : target,
beforeSend : function(){
$this.attr('disabled', true);
$this.find('i').hide().end().prepend(loading);
},
}).done(function(response){
$container.html(response);
$container.find('.modal').modal({
backdrop: 'static',
keyboard: false
}).modal('show');
}).fail(function(response, textStatus, xhr) {
}).always(function(){
isXmlHttpRequest = false;
$this.attr('disabled', false);
$this.find('img').remove().end().find('i').show();
});
});
$(document).on('click', '.modal-submit', function(event) {
event.preventDefault();
var $this = $(this),
$modalBody = $this.parent().parent().find('.modal-body');
$form = $modalBody.find('form');
$form.prop('action', $modalBody.data('action'));
$form.submit();
});
$(document).on('submit', '.modal-body form', function(event){
event.preventDefault();
var $this = $(this),
$elements = $this.find('input, select, button, textarea'),
$container = $($this.data('container'));
var ajax = $.ajax({
type : 'POST',
dataType : 'json',
url : $this.prop('action'),
data : $this.serialize(),
beforeSend : function() {
$elements.prop('disabled', true);
}
}).done(function(response) {
if (response.success) {
if (response.content) $container.html(response.content);
closeModal();
} else {
if (response.content) $this.parent().html(response.content);
}
if (response.messages.length) {
notifyAll(response.messages);
}
if (response.redirect) {
redirect(response.redirect);
}
}).always(function(){
$elements.prop('disabled', false);
});
});
Lastly just render the content in the required view script
// Create the URL target
$target = $this->url(
'route/path/name',
array(),
array('query' => array('format' => 'json'))
);
// Render the modal using the view helper
echo $this->modal(
'The modal title',
$this->form($this->form), // Use the form view helper to set the modal content
$target
);

how to send variable from gridview yii to javascript

i need your help. my purpose is update data in modal form, but i get problem and almost one week i didn't find the solution. the problem is i don't know how to send id from gridview to javascript function and in javascript function will throught to controller but in controller I can't get the variable of id. this my code.
//code in admin.php
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{view} {update} {delete} ',
'buttons'=>array(
'update' => array
(
'click'=>'js:function()
{
var idcab=($(this).parent().parent().children(":nth-child(1)").text());
editCabang(idcab);
$("#dialogClassroom").dialog("open");
}',
),
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
'id'=>'dialogClassroom',
'options'=>array(
'title'=>'Tambah Cabang',
'autoOpen'=>false,
// set to auto open for testing only
'draggable'=>true,
'resizable'=>true,
'closeOnEscape' => true,
// 'show'=>'fade',
// 'hide'=>'fade',
'position'=>array(300,50),
'modal'=>true,
'width'=>'700px',
'height'=>'auto',
'close' => 'js:function(event, ui) { location.href = "./admin" }'
),
));?>
<div class="divForForm"></div>
<?php $this->endWidget();?>
<script type="text/javascript">
function editCabang(idcab)
{
//alert(idcab); when i alert the id show
<?php echo CHtml::ajax(array(
'url'=>array('Tbcabang/update'),
'data'=> 'js:$(this).serialize(),"idcab2":$(this).idcab', //i want send variable idcab2 to controller
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
if (data.status == 'failure')
{
$('#dialogClassroom div.divForForm').html(data.div);
// Here is the trick: on submit-> once again this function!
$('#dialogClassroom div.divForForm form').submit(editCabang);
}
else
{
$('#dialogClassroom div.divForForm').html(data.div);
setTimeout(\"$('#dialogClassroom').dialog('close') \",3000);
}
} ",
))
?>;
return false;
}
//code in controller (update action)
public function actionUpdate()
{
//$id=100;
$id=$_POST[idcab2]; //the id is empty
$model=$this->loadModel($id);
if(isset($_POST['Tbcabang']))
{
$model->attributes=$_POST['Tbcabang'];
if($model->save())
{
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'success',
'div'=>"Tambah cabang berhasil"
));
exit;
}
else
// $this->redirect(array('view','id'=>$model->id));
$this->redirect(array('view','id'=>$model->id_cabang));
}
}
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'failure',
'div'=>$this->renderPartial('_form', array('model'=>$model), true,true)));
exit;
}
else
$this->render('update',array('model'=>$model,));
}
The expression js:$(this).serialize(),"idcab2":$(this).idcab doesn't make any sense..
How is $(this) going to work, and it should be just a javascript object..
To pass the idcab variable passed to the function to the controller you need to use just the idcab not $(this).idcab
There are various ways you can fix it . But what I get you want to show dialog for editing a grid so the best way is to to pass id to that dialog e. g
//code in admin.php
'class'=>'bootstrap.widgets.TbButtonColumn',
'template'=>'{view} {update} {delete} ',
'buttons'=>array(
'update' => array
(
'click'=>'js:function()
{
var idcab=($(this).parent().parent().children(":nth-child(1)").text());
//set the id
$("#dialogClassroom").dialog("option","idcab",idcab);
$("#dialogClassroom").dialog("open");
}',
),
Then add open event to dialog to fetch the data/or set the form :
'close' => 'js:function(event, ui) { location.href = "./admin" }'
'open' => 'js:function(event, ui) {
var idcab=$(ui).dialog("option","idcab");
//fetch the data for idcab and fill the dialog form , is that you want ?
//if yes call the ajax function now
}'
Probably you can set the open event function of dialog to set a hidden form field. You know what you are doing .

Categories