-
hmndAsked on August 23, 2018 at 3:14 PM
How can I make a custom API widget I make support the "count" function in form calculations?
-
hmndReplied on August 23, 2018 at 3:50 PM
For context, I'm looking to do something like that "count rows" feature in infinite lists for my own widget.
-
Elton Support Team LeadReplied on August 23, 2018 at 5:45 PM
Here's the documentation for Widgets.
https://developers.jotform.com/widgets
If you need further assistance, let us know.
-
hmndReplied on August 23, 2018 at 5:50 PM
That does not help me. The documentation is not complete and I still do not know how to support counting rows in my widget. I have figured that to make it appear as a table in submissions, I must put the selected options in an array of objects, however that does not make it possible for me to use the count function in form calculations.
-
Elton Support Team LeadReplied on August 23, 2018 at 7:22 PM
Basically, you have to count the number of rows or elements in your custom script. Then submit that value using JFCustomWidget.sendData(data) so it can be captured by the calculation widget.
Example:
JFCustomWidget.sendData({
'value': rowsCounter(),
});
...assuming the rowsCounter() is a function that counts the row
-
hmndReplied on August 23, 2018 at 8:34 PM
I want to return the data entered as well as the count though. Not just the count. The infinite list widget does this.
-
Elton Support Team LeadReplied on August 23, 2018 at 9:35 PM
Use JFCustomWidget.sendData(data) for the calculation and JFCustomWidget.sendSubmit(data) for submission with validation. It is in the widgets API.
Example:
//for calculation
JFCustomWidget.sendData({
'value': rowsCounter(),
});
//for submission
JFCustomWidget.subscribe('submit', function() {
JFCustomWidget.sendSubmit({
'valid': true,
'value': rowsData(),
});
});
You can also inspect the infinite list page (blank page) https://widgets.jotform.io/list/ and view its source. From there, you can see the minified scripts.
-
hmndReplied on August 23, 2018 at 9:36 PM
Oh! That's amazing. Thank you for your help!