Hi
I have these two CGridView buttons:
The generated code was working fine, with each button having a unique identifier (a.button1 and a.button2):
I added 'class_foo' to each button (used by jquery event delegation for further window-dressing):
However, now the generated code uses the same identifier (a.class_foo) for both buttons:
This causes both of the generated events to fire when only one of the buttons are clicked. The more buttons you have, the more submissions.
Can we add an 'id' to each button to keep their identifiers unique?
Thanx
I have these two CGridView buttons:
'button1' => array(
'label'=> $parent_model->myModelDescSingular . "'s " . $child_model->myModelDescPlural,
'icon' => false,
'imageUrl'=>Yii::app()->baseUrl.'/images/css/gridview/children.png',
'url'=>'$this->grid->controller->createUrl("update", array(
"parentID"=>$data->primaryKey,
))',
'click'=>"function(){
alert($(this).attr('href'));
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
fnc_maincode_child1div_in();
fnc_maincode_mainloading_out();
return false;
},
error:function(response){
return false;
}
})
return false;
}",
),
'button2' => array(
'label'=> $parent_model->myModelDescSingular . "'s " . $child_model->myModelDescPlural,
'icon' => false,
'imageUrl'=>Yii::app()->baseUrl.'/images/css/gridview/children.png',
'url'=>'$this->grid->controller->createUrl("childgrid", array(
"parentID"=>$data->primaryKey,
))',
'click'=>"function(){
alert($(this).attr('href'));
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
fnc_maincode_child1div_in();
fnc_maincode_mainloading_out();
},
error:function(response){
fnc_maincode_mainloading_out();
}
})
return false;
}",
),
The generated code was working fine, with each button having a unique identifier (a.button1 and a.button2):
$(document).on('click','#parent-grid a.button1',function(){
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
},
error:function(response){
fnc_maincode_mainloading_out();
}
})
return false;
});
$(document).on('click','#parent-grid a.button2',function(){
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
},
error:function(response){
fnc_maincode_mainloading_out();
}
})
return false;
});
I added 'class_foo' to each button (used by jquery event delegation for further window-dressing):
'button1' => array(
'label'=> $parent_model->myModelDescSingular . "'s " . $child_model->myModelDescPlural,
'icon' => false,
'imageUrl'=>Yii::app()->baseUrl.'/images/css/gridview/children.png',
'url'=>'$this->grid->controller->createUrl("update", array(
"parentID"=>$data->primaryKey,
))',
'options' => array(
'class'=> 'class_foo',
),
'click'=>"function(){
alert($(this).attr('href'));
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
fnc_maincode_child1div_in();
fnc_maincode_mainloading_out();
return false;
},
error:function(response){
return false;
}
})
return false;
}",
),
'button2' => array(
'label'=> $parent_model->myModelDescSingular . "'s " . $child_model->myModelDescPlural,
'icon' => false,
'imageUrl'=>Yii::app()->baseUrl.'/images/css/gridview/children.png',
'url'=>'$this->grid->controller->createUrl("childgrid", array(
"parentID"=>$data->primaryKey,
))',
'options' => array(
'class'=> 'class_foo',
),
'click'=>"function(){
alert($(this).attr('href'));
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
fnc_maincode_child1div_in();
fnc_maincode_mainloading_out();
},
error:function(response){
fnc_maincode_mainloading_out();
}
})
return false;
}",
),
However, now the generated code uses the same identifier (a.class_foo) for both buttons:
$(document).on('click','#parent-grid a.class_foo',function(){
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
},
error:function(response){
fnc_maincode_mainloading_out();
}
})
return false;
});
$(document).on('click','#parent-grid a.class_foo',function(){
$.fn.yiiGridView.update('child-grid', {
type:'POST',
url:$(this).attr('href'),
success:function(response) {
$('#child1Div').html(response);
},
error:function(response){
fnc_maincode_mainloading_out();
}
})
return false;
});
This causes both of the generated events to fire when only one of the buttons are clicked. The more buttons you have, the more submissions.
Can we add an 'id' to each button to keep their identifiers unique?
Thanx