Count for Custom Widget

  • Profile Image
    hmnd
    Asked on August 23, 2018 at 03:14 PM

    How can I make a custom API widget I make support the "count" function in form calculations?

  • Profile Image
    hmnd
    Answered on August 23, 2018 at 03:50 PM

    For context, I'm looking to do something like that "count rows" feature in infinite lists for my own widget.


  • Profile Image
    EltonCris
    Answered on August 23, 2018 at 05:45 PM

    Here's the documentation for Widgets.

    https://developers.jotform.com/widgets

    If you need further assistance, let us know.

  • Profile Image
    hmnd
    Answered on August 23, 2018 at 05: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.

  • Profile Image
    EltonCris
    Answered on August 23, 2018 at 07: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

  • Profile Image
    hmnd
    Answered on August 23, 2018 at 08: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. 

  • Profile Image
    EltonCris
    Answered on August 23, 2018 at 09: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.

  • Profile Image
    hmnd
    Answered on August 23, 2018 at 09:36 PM

    Oh! That's amazing. Thank you for your help!