Editor posts first value of select, even if it doesn't change, if I click somewhere on the row
Editor posts first value of select, even if it doesn't change, if I click somewhere on the row
I'm using inline edit, and have created a select with some values from the database.
When I select a value, and with the mouse click on another row, this is posted:
{"action"=>"edit", "data"=>{"10"=>{"event_type_id"=>"4"}}, "captures"=>[], "id"=>"10"}
This is, event_id 10, telling me that I've chosen nr4 in the list.
The server replies:
{:data=>#<Event @values={:event_id=>10, :event_type_id=>4, :publisher_id=>1, :name=>"Signering2", :description=>"", :period=>#<Sequel::Postgres::PGRange:0x000000068a56c8 @begin=nil, @end=nil, @empty=false, @exclude_begin=true, @exclude_end=true, @db_type="daterange">, :updated_at=>2018-06-03 20:57:37 +0200, :created_at=>2018-05-31 15:01:37 +0200}>}
Everything looks good.
BUT, if I click on another cell, name for example, and change the name, this happens.
{"action"=>"edit", "data"=>{"10"=>{"name"=>"SigneringWOHO", "event_type_id"=>"1"}}, "captures"=>[], "id"=>"10"}
It sends event_type_id with the first value in the select.
If I click on the name cell, and doesn't change anything. This is what happens.
{"action"=>"edit", "data"=>{"10"=>{"event_type_id"=>"1"}}, "captures"=>[], "id"=>"10"}
It sends the first value from the select control anyway.
I can't get around this. I've tried with submit on change, submit only changed, submit all etc..
This is my editor config:
65 editor = new $.fn.dataTable.Editor( {
66 ajax: {
67 edit: {
68 type: 'PUT',
69 url: '/events/id/.json'
70 },
71 },
72 table: "#events",
73 idSrc: 'event_id',
74 fields: [ {
75 label: "Name",
76 name: "name",
77 }, {
78 label: "Händelsetyp",
79 name: "event_type_id",
80 type: "select",
81 options:
82 #{ets.to_json.html_safe}
83 }, {
84 label: "Beskrivning",
85 name: "description"
86 }, {
87 label: "Datum",
88 name: "period"
89 }]
90 });
91
92 $('#events').on( 'click', 'tbody td:not(:first-child)', function (e) {
93 editor.inline( this, {
94 onBlur: 'submit'
95 } );
96 } );
What am I doing wrong?
Answers
Can this be the problem?
options:
{"Ospecificerad":1,"Utgivning":2,"Marknadsaktivitet":3,"Signering":4,"Exponering i media":6}
},
The error suggests that the value for the field that is being edited (
event_type_id
in this case) is not in the list of options for theselect
list.If you have a link to the page you can give me I can take a look.
Allan
That's very kind of you! Unfortunately I'm unable deploy this outside my own machine at this moment. I'll try to think of something.
So, given you are right.
1. Why does it post the correct values the first time?
2. If I remove the select, the editor behaves as expected. But if I add it, it posts the first select value every time I click on the row, even if nothing is changed?
3. I have a breakpoint on the onClick event. But it doesn't fire until I click the second time. First click enables editor but it doesn't brake, next click in same box fires event.
Given the information in point 3, would it be possible that the datatable gets the first click, or that somehow things happens twice for some reason? If I click the select, and selects the last value, and then click on another row, it submits perfectly. But if I tab to the next field it submits perfectly, and then submits first value again.
Thanks again for a quick reply and a great product!
Hm, I think i'm on to something, hold your horses!
Yes, you were right.
The datatable shows the event type name, the editor shows correct name and posts correct value, but I guess it never gets the value properly set, only the the name. Therefore it's always wrong value.
Thanks for pointing it out
Thanks for the clarification! I stumbled over this as well. Used slightly different words in ajax responces where no option values existed for in the select field. But it kind of worked (i thought so) - that's why the mistake is hard to catch.
The problem was: when inline editing a text field in a table row, it was sending from the unedited inline select box in the same row always the first option as well, even when no changes were made to this selection box.
..just for the record and others searching for the same problem.. :-)