Using a custom JS script to handle a large number of rules on a condition?

  • markashton
    Asked on October 3, 2014 at 12:22 PM

    Hi,

    Is there a limit on the number of rules one can set on a condition?

    And/Or ...

    Is there an interface issue with regard to adding many rules to a condition ... like will it run out of space ;-?

    I will require, for a single form, one condition with 1500 rules ...

    Why?

    The condition is to update a form field value ... I will have to add 1500 of these rules ... because I have 1500 names (there will be a couple of other conditions too but with only a few rules) ... is there a better way of doing this with conditions??

    Using a custom JS script to handle a large number of rules on a condition? Image 1 Screenshot 20

     

    Thnaks Mark

  • David JotForm Support
    Replied on October 3, 2014 at 1:05 PM

    Hi,

    Though my answer would normally be "Unlimited" for most users, you are not most users.  I'll go ahead and pass this along to our dev's to see if there is indeed a hard cap or any performance loss issues with adding this many.  As manually testing this would take a substantial amount of time for both you and me to do, I would rather ask before proceeding. 

    If you need different values output to another field based on 1500 different names, I believe the way you are going about it may be the only solution. 

  • Steve VP of Sales Operations
    Replied on October 3, 2014 at 10:09 PM

    Hello Mark-

    We heard back from our developer, and as you may expect the idea of 1500 rules gave him pause for concern. 1500 of any sort of conditional check in JS would likely hog a lot of resources and cause the system to freeze.

    Our response is no, we don't support 1500 rules, but don't have a fixed upper limit implemented. Our dev requested more time to evaluate that and will provide an update if a clear answer can be provided.

    This question highlights a common question that comes up. JF is obviously a generalized tool that provides many customizations. These customizations can't be optimized in the same way a manually built form could be. It saves tons of time on development, at some expense to performance. In this case, the performance hit would almost invariably break our system. Thus the solution is to build the customizations by hand. The process isn't that hard actually, and the JavaScript sounds like it'd be fairly straightforward.

    - build the form in JF, without the conditions.

    - download the full source code

    - add a custom JS script that conducts the checks/field updates that you'd like.

    I'm under the impression you're a coder, but if you'd like assistance with that we frequently help out with these sorts of scripts.

    Regards

  • markashton
    Replied on October 5, 2014 at 4:45 AM

    Steve,

    That seems like a great suggestion - the JS script route.

    I'm not actually a 'hard' coder but I am a website developer.

    With regard to the JS script would you be most kind as to just give me a pointer in terms of its content. I'd be most grateful.

    Essentially, each name updates a couple of fields with text.

    If you could give me a lead on that I'll pay your mortgage for a month ;-)

    Thanks Mark

  • Ben
    Replied on October 5, 2014 at 6:46 AM

    Hi Mark,

    It is usually the best to have a jotform created first then we can easily create a javascript that would work on it.

    The idea for it would be to grab the ID of the Full name field and match it against the values array.

    Lets say for now, as an example that the ID of this box is "fullname" and that the field that you want to update has an id of 'resultfield'.

    var agents = ["Hannah Watts","Hajar Alafifi","...."];

    var v = $("#fullname").val(); //we can use .text() as well..

    Now we just need to match it against the array and that can be done like so:

    if($.inArray(v, agents) != -1)
    {
      //It is in the array
      $("#resultfield").text() = 'CMI'
    }

    Once your jotform is creates however we can take a closer look and provide you with the exact code. I should mention that the above code was not tested out as I wrote it as an example, although it should work.

    Do let us know if you have any further questions.

    Best Regards,
    Ben

  • markashton
    Replied on October 5, 2014 at 3:12 PM

    Hi Ben,

    A simple jotform with everything required is this: 

    http://form.jotformpro.com/form/42733018755961

    The Full name is actually an Autocomplete field

    Depending on the Full name added ... the other two fields are then filled accordingly ... as you well know from your example above.

    So, my requirement is simple ... to prefill the two fields based on the name ... of course the 1500 names is the problem so I am very grateful you advised of this solution.

    A working proof of concept would be fantastic ... using the two names you have used ... I'll be in your debt ;-)

    Many Thanks for your valued help.

    Regards Mark

  • Steve VP of Sales Operations
    Replied on October 6, 2014 at 7:30 PM

    Hello Mark-

    Give us a couple days to put this together. We should have a proof of concept by the end of the week at the latest. As you note, this is the right way to solve the issue since manually entering 1500 names through our form would be quite tedious.

    Regards

  • markashton
    Replied on October 7, 2014 at 4:48 PM

    Thanks Steve,

    That would be fantastic. I

    Many Thnaks Mark

  • Steve VP of Sales Operations
    Replied on October 9, 2014 at 8:43 PM

    Hello Mark-

    It's been a super hectic week, but wanted to get a demo out to you. This only updates one field and it's always to the value 'CMI'. What I imagine you want are a series of lists of names, each of which maps to different values for the other fields. Once this is integrated in your system, that should be easy to update.

    Here's how to see the working demo:

    - download the full source code of the form. I used a clone of your form:

    http://www.jotformpro.com/form/42801489428966

    Instructions on downloading full source code: http://www.jotform.com/help/104-How-to-get-the-Full-Source-Code-of-your-Form

    - directly above the closing body tag < / body >, place this code:

    http://pastebin.com/YYp8N70G

    That should work if embedding the code in a standalone html page. If you're using a CMS, such as wordPress, there are other considerations. More info on that can be found here:

    http://www.jotform.com/answers/405474-Multiple-selection-checkbox-with-excluded-single-check#407145

    Also, one task that can be done with a simple script is converting a long list of names into comma separated values. Please take a look at this POC, and if we get to the point of needing the 1500 list of CSV names, we can assist with that.

  • markashton
    Replied on October 10, 2014 at 7:00 AM

    Hi Steve,

    Thanks for all your effort. I greatly appreciate it.

    Unfortunately, I can't make it work ... but as all the code necessary is in the hosted html file it should be easy to work out what the problem is.

    What did I do?

    I cloned your form
    I copied the full source code ... created an html document here:

    http://test.workflows-demo.me/test.html

    Please check the source code ... I have pasted the javascript before the closing body tag ... the input references appear to be correct i.e. input_5 and input_7

    Am I miossing something? The autocomplete works nicely ... but no desired pre-fill/update field function.

    Hope you can help.

    Thanks Mark

     

  • Steve VP of Sales Operations
    Replied on October 10, 2014 at 5:16 PM

    Hello Mark-

    I looked at this and looks like it only works properly in FireFox. It doesn't work immediately in Chrome. I will look into that and figure out what's going on.

     

     

  • Steve VP of Sales Operations
    Replied on October 10, 2014 at 7:15 PM

    Mark-

    Apologies for the bug in the first response. For anyone who's curious, I believe this was the cause. It's related to the autocomplete function not working well with the change event.

    Please replace the bottom script with this version.

    http://pastebin.com/ACVvX3ND

    Note that this version makes the field update after the user clicks away from the name field, as opposed to after the name field has changed but the user is still focused on it. Here's a demo that works for me across FF/Chrome/Safari/IE8/IE10:

    https://shots.jotform.com/steve/test/home.htm

    Let me know what you think.