How to refresh a form on field change

Help
2011-10-28
2013-04-25
  • Hi guys,

    Do you have an example please, where if I make a selection from a field, it will refresh the documenmt. Other field values may depend on my selection. If it has anything to do with a Javascript event, could you please explain how to integrate javascript into the plomino form.

    thanks in advance
    Eliott

     
  • Jean Jordaan
    Jean Jordaan
    2011-11-01

    You could see how far dynamic hide-when's get you.

    Alternatively, add a "Computed for Display" field to the form, and have it return the JS you need:

    """
    html = """<script>
    // JS goes here.
    </script>""" % (params)

    return html
    """

     
  • Jean Jordaan
    Jean Jordaan
    2011-11-01

    Edit: Alternatively, add a RICHTEXT "Computed for Display" field to the form …

     
  • For anyone interested in a solution, it is done via JavaScript, assign a field onchange event to a function and set up the function to submit the form. To open the form in edit mode, include this line in the OnSave event of the form, and your have the power ;-)

    1. Create a computed rich text field, with fomula:
    html= """<script>

    // load the onchange event for all required fields
    topcat = document.getElementsByName("DocTopCat");
    subcat = document.getElementsByName("DocSubCat");
    topcat.onchange = lookup;
    subcat.onchange = lookup;

    function lookup() {
       document.forms.submit();
    }

    </script>"""
    return html

    2. in the form, add at the end of the On Save event the line
    ….
    return plominoDocument.absolute_url() + '/EditDocument'

    It works! This gives Plomino the power of the Lotus Notes to refresh form on keyword change. This should be added to the Plomino How-To documentation as a basic feature.

    Regards

     
  • Jean Jordaan
    Jean Jordaan
    2012-01-12

    @eminkovitch , cool :-)

    Eric's suggestion (to use dynamic hidewhen's) doesn't require Javascript hackery or page reloads, but it has the drawback that all fields on the form are loaded immediately. This could be an issue if some are heavy, but for light fields, it's best. Also, it doesn't handle setting a default for a dependent field based on other field choices, I think.

    You're very welcome to package your method into a small sample database -- maybe it can be featured on plomino.net !

     
  • Sure, I will be happy to do that. I may have other stuff to contribute as well, a Knowledgebase I've started and I can share that. It contains many of the things I have learned from these chats as well. Just let me know where I can put them, or where to send a URL.

    Cheers
    Eliott

     
  • Eric Brehault
    Eric Brehault
    2012-01-16

    Sure :)
    That's excellent work Eliott !

    I have created an account for you on plomino.net (you should received an email), it will allow you to add content in http://www.plomino.net/how-to
    and in
    http://www.plomino.net/samples

    It would a wonderful contribution if you could enter your how-tos and samples.

    Eric