Display of editable select widget in list view

196 views
Skip to first unread message

karlb...@gmail.com

unread,
Dec 16, 2015, 9:34:53 AM12/16/15
to Xataface
After following Steve's tutorial on http://xataface-tips.blogspot.nl/2014/04/editable-select-widget-in-list-view.html I got the select widget working on valuelists where the actual value and label are identical. But I want to show the label and edit the actual value. Currently it the edit doesn't save into the record. I got as far as letting the select list the right label (I changed $record->val() into $record->display()), but changing it doesn't save the value. Here is my code:

Table delegate:
function TrackPrio__renderCell(Dataface_Record $record){
   Dataface_JavascriptTool::getInstance()->import('editable_status.js');
   $query = Dataface_Application::getInstance()->getQuery();
   $table =& Dataface_Table::loadTable($query['-table']);
    $options = $table->getValuelist('Prio');
   $currVal = $record->display('TrackPrio');
   $out = array();
   $out[] = '<select class="status-drop-down" 
     data-record-id="'.htmlspecialchars($record->getId()).'">';
   foreach ( $options as $opt ){
     $selected = ($currVal === $opt) ? 'selected':'';
     $out[] = '<option value="'.htmlspecialchars($opt).'" '.$selected.'>'
       .htmlspecialchars($opt).'</option>';
     
   }
   $out[] = '</select>';
   return implode("\n", $out);
 }

valuelists.ini:
[Prio]
0="None"
1="Very Low"
2="Low"
3="Medium"
4="High"
5="Critical"

I guess I have to change value="'.htmlspecialchars($opt).'", but I can't seem to figure out into what exactly.

karlb...@gmail.com

unread,
Dec 16, 2015, 9:57:38 AM12/16/15
to Xataface
Upon testing upon another field without the $record->val() into $record->display() change, it seems this doesn't work either, so the problem might be with the javascript:

(function(){
var $ = jQuery;
registerXatafaceDecorator(function(node){
$('select.status-drop-down[data-record-id]', node).change(function(){
 var recordId = $(this).attr('data-record-id');
 xataface.IO.update(recordId, {status : $(this).val()}, function(res){
   if ( res && res.code == 200 ){
     alert('Issue updated successfully');
   } else if ( res && res.message ){
     alert('Failed to update issue: '+res.message);
   } else {
     alert('Failed to update issue.  Check server log for details');
   }
 })
});
});

})();



Op woensdag 16 december 2015 15:34:53 UTC+1 schreef karlb...@gmail.com:

Steve Hannah

unread,
Dec 16, 2015, 11:33:30 AM12/16/15
to xata...@googlegroups.com
How are you embedding the javascript?  Are you sure it's being picked up at all.

Try adding something like alert('test') just before or after the "var $ = jQuery" and see if it pops up on page load.

Also double check "$(this).attr('data-record-id');".  I think the attribute might be "data-xf-record-id".

Steve

--
You received this message because you are subscribed to the Google Groups "Xataface" group.
Visit this group at https://groups.google.com/group/xataface.
To view this discussion on the web visit https://groups.google.com/d/msgid/xataface/3c5a97b1-7b2f-44c2-82e9-99914796a853%40googlegroups.com.



--
Steve Hannah
Web Lite Solutions Corp.

karlb...@gmail.com

unread,
Dec 17, 2015, 8:47:19 AM12/17/15
to Xataface
The javascript works, I even get the message "updated successfully". After changing data-record-id to data-xf-record-id on every occurrence, the result is the same: I get the success message, but the change isn't saved. Using the Chrome debug tool I don't see anything happening that makes sense to me (my js-skills are practically non-existent). This is all I can find, maybe it's of use:
XHR finished loading: POST "https://[domain].com/index.php".
send
@ jquery.packed.js:6
m
.extend.ajax @ jquery.packed.js:6
m
.(anonymous function) @ jquery.packed.js:6
update
@ index.php?-action=js&--id=global.js-fbf9a3ac6727b0b25b53f4a9cfb828a4:82
(anonymous function) @ index.php?-action=js&--id=global.js-fbf9a3ac6727b0b25b53f4a9cfb828a4:87
m
.event.dispatch @ jquery.packed.js:5
r
.handle @ jquery.packed.js:5


Op woensdag 16 december 2015 17:33:30 UTC+1 schreef Steve Hannah:

karlb...@gmail.com

unread,
Mar 4, 2016, 7:05:24 AM3/4/16
to Xataface
I've actually found the issue: the field I wanted to update is not status but TrackStatus, so I had to change the parameter in xataface.IO.update.

Is there a way to make this variable? This way I need a new script for every field I want to make editable in the list view. I tried it by adding a new attribute to the select field called fieldName and called it with 
var fieldName = $(this).attr('fieldName');
and this shows the correct fieldname when I put it in an alert, but when I put it instead of status/TrackStatus as a parameter I can't get it to work.
Any ideas how to do this?

Thanks!



Op woensdag 16 december 2015 17:33:30 UTC+1 schreef Steve Hannah:
How are you embedding the javascript?  Are you sure it's being picked up at all.
Reply all
Reply to author
Forward
0 new messages