infinite process running during dependent call
infinite process running during dependent call

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
Hi, I am experiencing a couple of issues when using the editor and the dependent function to update a field value which I believe may be related, my console is reporting an error Unchecked runtime.lastError: The message port closed before a response was received
The line 844 shown in the attached screen shot is running in an infinite loop
The section of client code is shown below which updates a total editor field as shown below
siteEditor.dependent( 'dm_holdings.total', function ( val, data ) {
var stock_id = Number(siteEditor.field('dm_holdings.stock_id').val());
var quantity = Number(siteEditor.field('dm_holdings.quantity').val());
var price = Number(siteEditor.field('dm_holdings.price').val());
var total;
total = price * quantity / 100;
console.log('line 844, siteEditor.dependent dm_holdings.total / total:',total);
siteEditor.set('dm_holdings.total', (total));
});
The system adds a row successfully to the table, but simply leaves this process running indefinitely in the background.
I can provide access details to my system by PM, otherwise you may have received them already, with thanks.
Client File to Edit
https://www.dividendview.co.uk/wp-admin/post.php?post=28516&action=edit
Run Client File Page
https://www.dividendview.co.uk/stock-holdings/
Any help much appreciated.
Best regards
Colin
This question has accepted answers - jump to:
Answers
Can you try calling the callback, like in this example here, please. Without it, you may see what you've described,
Colin
Hi Colin
I have added the callback as above and I am no longer getting the error message
Unchecked runtime.lastError: The message port closed before a response was received
, so thats good news.The
line 844, siteEditor.dependent dm_holdings.total
process however is still running endlessly, until the page is refreshed.I am getting the same problem on a number of my scripts, as they all use the same dependent functionality.
any other thoughts ?
Thanks
Colin
Hi Colin
Did you have any suggestions on a fix for this problem of the endless process, as it will prevent me from being able to go live in the near future.
You can access my system as before if that makes it easier to solve.
Best regards
Colin
Hi
I may have the answer, an alternative to dependent given below, will test when. I get home
https://editor.datatables.net/reference/api/field().input()
I will update post if it works
Regards
Colin
I think I understand - rather than the process hanging, the function is being called infinitely.
That is because you are setting the value of
dm_holdings.total
inside a dependent function:So yes, the value change would then trigger the dependent update, and thus cause an infinite loop.
Do you not want to have the
total
field dependent on the three other fields?Allan
Hi Allan
Thanks for getting back, you are absolutely correct my silly mistake..
the lines should be
siteEditor.dependent( 'dm_holdings.quantity', function ( val, data, callback ) {
... etc.
total = price * quantity / 100;
siteEditor.set('dm_holdings.total', (total));
it also works using
siteEditor.field( 'dm_holdings.quantity' ).input().on( 'change', function () {
My only problem is I would like the total to update as you type the quantity into the field, whereas it only updates after moving to another field or creating the record.
so say a price of 150 in pence, set after stock selection
quantity 1000, should
display
total 1.5 (in GBP) when quantity 1
total 15 when quantity 10
..etc.
total 1500 when quantity 1000
The stock selection updates price on selection using the dependent function, but is this possible in this instance when typing a number into a text field.
I am also still getting this error
Unchecked runtime.lastError: The message port closed before a response was received.
after adding
callback(true);
It does not appear to adversely impact on functionality, but I maybe wrong.
Thanks
Colin
You can tell
dependent()
to use an event other than it's default ofinput
- e.g. you could usekeyup
. See the final example on thedependent()
documentation for how to do that.Should be
callback({})
I think.Allan
Hi Allan
Many thanks, I think it will make a big difference if the calculation is done whilst typing.
I will give your suggestion a try tomorrow.
Best regards Colin
Hi Allan
All working by adding to end of dependent event as follows
siteEditor.dependent( ['dm_holdings.quantity', 'dm_holdings.price'], function ( val, data, callback ) {
and at the end
}, {event: 'change keyup'} )
Many thanks
Colin