Render checkbox in list tab

182 views
Skip to first unread message

STeve Fish

unread,
May 13, 2014, 5:10:32 AM5/13/14
to xata...@googlegroups.com

Hi all,
I'm attempting to design a replacement for the standard select record checkbox that I can sort/filter on and also use to select points on map that is derived from the same table.

I have managed to have checkboxes appear in the list tab but not have them display the boolean (tinyint(1)) value in the underlying field.

I have been hacking around with the example found at http://xataface-tips.blogspot.com.au/2014/04/editable-select-widget-in-list-view.html (Editable Select Widget in List View) but not managed to get it working. 

I did manage to get the select drop down box in the example working fine

Here is one of my hackish attempts in the table delegate class:

  function SELECT__renderCell(Dataface_Record $record){
     Dataface_JavascriptTool::getInstance()
      ->import('editable_SELECT.js');
 
    $currVal = $record->val('SELECT');
    $out = array();
$out[] = '<input type="checkbox" class="select-checkbox" checked="if ('.htmlspecialchars($record->strval('SELECT')).'==0){&quot;true&quot;;} else {&quot;false&quot;;}" data-record-id="'.htmlspecialchars($record->getId()).'">';
$out[] = '</input>';
    return implode("\n", $out);
  }

I won't post the editable_SELECT.js because I don't believe that is part of the problem (yet).

Any tips, pointers in the right direction are greatly appreciated.
Regards,
Steve F

Steve Hannah

unread,
May 13, 2014, 12:20:45 PM5/13/14
to STeve Fish, xata...@googlegroups.com
Unless your editable_SELECT.js is performing some post-load processing of the "checked" attribute, I don't believe that this will do anything:
checked="if ('.htmlspecialchars($record->strval('SELECT')).'==0){&quot;true&quot;;} else {&quot;false&quot;;}"

Rather, I would do something like:
...
$checked = intval($record->val('SELECT')) === 0 ? 'checked="checked"' : '';
$out[] = '<input type="checkbox" class="select-checkbox" '.$checked.' data-record-id="'.htmlspecialchars($record->getId()).'">';
...

Steve
--
Steve Hannah
Web Lite Solutions Corp.

STeve Fish

unread,
May 13, 2014, 7:34:24 PM5/13/14
to xata...@googlegroups.com, STeve Fish
Thanks Steve 

$checked = intval($record->val('SELECT')) === 1 ? 'checked="checked"' : '';
 with a 1 works.

For any one else looking at this post for help with checkbox editing in list view (and just in case Steve has a comment)  here is my working editable_SELECT.js:

//require <jquery.packed.js>
//require <xataface/IO.js>
(function(){
  // Get a short handle to the jQuery object
  var $ = jQuery;
    //registerXatafaceDecorator() is like $(document).ready() except that it may also be called
  // when a node is loaded via ajax.
  registerXatafaceDecorator(function(node){
    $('input.select-checkbox[data-record-id]', node).change(function(){
      var recordId = $(this).attr('data-record-id');
  if($(this).attr('checked') === 'checked') {$checked = 1;} else {$checked = '';};
       xataface.IO.update(recordId, {SELECT : $checked}, function(res){
        if ( res && res.code == 200 ){
 showAlert('saved');
        } else if ( res && res.message ){
showAlert('Notsaved');
          alert('Failed to update SELECT: '+res.message);
        } else {
showAlert('Notsaved');  //showAlert is a function to display a 1 second duration 'saved' pop-up instead of the alert message
          alert('Failed to update SELECT.  Check server log for details');
        }
      })
    });
  });

And my working delegate class 'trees.php':

  function SELECT__renderCell(Dataface_Record $record){
 
     Dataface_JavascriptTool::getInstance()
      ->import('editable_SELECT.js');
 
    $currVal = $record->val('SELECT');
    $out = array();
$checked = intval($record->val('SELECT')) === 1 ? 'checked="checked"' : '';
$out[] = '<input type="checkbox" class="select-checkbox" '.$checked.' data-record-id="'.htmlspecialchars($record->getId()).'">';
$out[] = '</input>';
    return implode("\n", $out);
  }

Regards and thanks,
Steve F
Reply all
Reply to author
Forward
0 new messages