⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

callback from a toggle on the list?



richb201
  • profile picture
  • Member

Posted 28 December 2017 - 00:27 AM

I have setup my list with checkboxes in the first column. I'd like to have a callback when a user clicks on one of the check boxes, so I can clear the other ones. This is kind of like a radio button. I have been working my way through the callbacks but haven't found one that will allow me to clear all the checkboxes so the user can check one of their choice. Is there anyway to do this? I am not a very sophisticated js developer, btw. I have managed to use callback_column and I could see using that to clear the all check boxes, but I need to do it right after a user places the mouse in the area but before they click on the new checkbox. 

 

Any ideas or am I going down the wrong path? 


Amit Shah
  • profile picture
  • Member

Posted 28 December 2017 - 04:46 AM

/topic/421-multiple-delete-selection/

 

 

Above is the post you can refer to for the development of your solution.

 

 

Happy Gcing :)


richb201
  • profile picture
  • Member

Posted 28 December 2017 - 07:42 AM

Thanks. I saw that. But I have no idea of where this goes?

 

$('#report-success').html("<p>Your data has been successfully updated</p>").slideDown();

 

Here is my guess. Let me know if I am on the right track?

 

in my controller in the function that I am using.

$crud->set_js('js/js_func.js');

 

in a file called js_func.js in the js directory under my prject. 

 

window.onload=function(){

$("a[title='All Comments']").click(function(e) { //// here u should place any title of the button you want to hook to
e.preventDefault(); //This is a must - it will bock any action provided by u on click of the button
alert("I was clicked"); ///Here is where u add whatever action you want to assign to.
});
}

 

When I look in the $CRUD I see js_files is set to http://localhost/js/js_func.js which is the js directory in my project directory. 

 

I did put a breakpoint in the js_func.js module in the onload, but it doesn't get fired.  I also don't see the created button. 

 

thx


Amit Shah
  • profile picture
  • Member

Posted 29 December 2017 - 07:38 AM

Well it will be difficult to guess up the issue unless the code is seen in or played around with...

If the file is being called and if it exists in the set path, you just need to make sure you writing in the right conditions for it to execute.

 

1 thing - keep in mind - if you have multiple window.onload - it will fail for sure cuz the latest one will override the other one.. This issue i encountered very recently and thats the reason i thought should share you first hand.

 

Happy GCing :)


richb201
  • profile picture
  • Member

Posted 29 December 2017 - 14:37 PM

Well, I can see that when I click on the radio button I am getting a #document.mouseup event. This is what I am seeing in my chrome debugger. So I know a mouse button was clicked but have no idea if it was on one of the check boxes, which is the only event I want to catch. Anyone have any ideas?

 

 

 

  1. Local
    1. a:MouseEvent {isTrustedtruescreenX-1496screenY428clientX24clientY312, â€¦}
    2. arguments:Arguments [MouseEventcalleeÆ’Symbol(Symbol.iterator)Æ’]
    3. this:document
    4.  
    5.  

Amit Shah
  • profile picture
  • Member

Posted 29 December 2017 - 17:40 PM

Well i cant say if you are on the right track or not, but what i will do here is  - give u a simple steps that can help u check if you got it right or not..

You can refer the same in the code link shared

1. Add a js that will hook on change of any checkbox state ...

2. If there is any checkbox checked, it will show up the button / enable the action button

3. If in case none of the checkboxes are checked, it will disable the button.

4. On click of the action button, it collects the ID's of all the rows for which the checkbox was checked and it will then pass it on to the relevant action..

 

This is what you need to focus on building up to create ...!!

 

Hope this gives u idea to go ahead with building the solution


richb201
  • profile picture
  • Member

Posted 29 December 2017 - 20:37 PM

I am stuck at step one.

 

$jsfile ='js/js_func.js';
$crud->set_js($jsfile);

$crud->callback_column('active',array($this,'add_field_callback_1'));

 

 

public function add_field_callback_1($value, $row)
{
          return '<input type="checkbox" name="checkbox">';
}

 

This SHOULD set each 'active' field on the list to a checkbox. This works. 

My problem is getting notified that now the checkbox has been checked. 

 

In my js file I have this currently but I have tried at least 10 different things. The js code never gets called. I know this because I have set a breakpoint on the first line of this. It never gets fired and I can change the js code a thousand more  times, it will never be called. 

 

window.onload{

$('input:checkbox').change(function () {
var name = $(this).val();
var check = $(this).attr('checked');
console.log("Change: " + name + " to " + check);
});
}

 Perhaps it is the window.onload being the wrong event. Or perhaps the js path is wrong. 


Amit Shah
  • profile picture
  • Member

Posted 30 December 2017 - 05:05 AM

Well - i agree, there are times when there are multiple instance of window.onload - the last one takes up on the precedence and the earlier ones dose not get executed.

I have faced this issue myself. .... I have came up with other solution that might work for you ...

 

document.onreadystatechange = () => {
  if (document.readyState === '/complete') {
    //.....DO YOUR MAGIC HERE
  }
};

 

 

Hope this will help you get your solution through.

 

Happy GCing :)


richb201
  • profile picture
  • Member

Posted 30 December 2017 - 15:22 PM

Thanks for the pointer. I have started down a different path. Since I can't seem to catch the 'checkbox being checked event', I decided to get rid of the checkboxes. I replaced it with an add_action  with the button labeled "Make Active" as you can see on the attachment. In the upper right you can see the "Active Company or Division:". Right now I have the string "Hi there".  My plan is to change that string via the Make Active button. So there are two things I need to do to mke this work.

 

1) be able to set the "Hi There" text to whatever Company call back was pressed.

2) store the last company active in a cookie or some other global storage for this user, so next time they log in the same Make Active company is used. 

 

I added the Make active button with:

 

$crud->add_action('Make Active', '', '','ui-icon-plus',array($this,company_update'));

 

 

when someone presses the Make Active button on a specific line, I want to a) store the company in a global variable B) write it to a system cookie c)change the text "Hi There" to the name of that company (perhaps on a colored background). 

 

I see another problem too. The call function is

 

function company_update($primary_key , $row)
{
echo($row->company_division);
}

 

when I hook the callback on by using $crud->add_action, the callback is being fired initially once for each line. I only want it to fire when a user presses the Make Active button. Any idea how to stop the initial firing?


richb201
  • profile picture
  • Member

Posted 30 December 2017 - 18:56 PM

I did a little more research on callbacks in codeigniter. I see that a callback needs to return a built route. The documentation is really lacking. OK let's say I change the callback to

 

function company_update($primary_key $row)
{
return("Configure/update_current/".$row);

}

 

and then add a function in the Configure controller

 

function update_current($row)

{

echo ($row->company);

}

 

Is this what is needed? Will this stop update_current from being called for each row during the initial render?