Menu

Implementation of "submit" f...

2011-11-23
2012-09-09
  • Vasanth Kamatgi

    Vasanth Kamatgi - 2011-11-23

    The submit "field" is always implemented as

    <input type="submit" [b]name="submit"[/b] id="..."/>  The attribute name is [i]hardcoded[/i] to always have a value of "submit".  This results into a situation where javascript form.submit() method cannot be invoked on the form without tweaking the submit button first.  I was wondering if it is an unintentional consequence or a conscious decision to prevent the developers from using submit() method on the form in javascript.
    
     
  • David E. Jones

    David E. Jones - 2011-11-23

    Sorry, I haven't run into this issue. Could you provide more details about
    what you tried to do and what happened (and in which browser, etc)?

     
  • Vasanth Kamatgi

    Vasanth Kamatgi - 2011-11-23

    I have a form definition like this:

            <form-single name="SelectPublicationGroup" transition="../new">
                <field name="publicationGroupId">
                    <default-field title="Publication Groups">
                        <drop-down current-description="[Select]"
                            no-current-selected-key="_NA_">
                            <entity-options key="${publicationGroupId}" text="${publicationGroupName}">
                                <entity-find entity-name="PublicationGroup" cache="true">
                                    <order-by field-name="seqNumber" />
                                </entity-find>
                            </entity-options>
                        </drop-down>
                    </default-field>
                </field>
                <field name="create">
                    <default-field title="Create New">
                        <submit />
                    </default-field>
                </field>
                <field-layout>
                    <field-row>
                        <field-ref name="publicationGroupId" />
                        <field-ref name="create" />
                    </field-row>
                </field-layout>
            </form-single>
    

    I bound an event on the drop-down for onchange, which is supposed to
    submit the form like this:

        jQuery("#SelectPublicationGroup_publicationGroupId").change(function(){
            document.forms['SelectPublicationGroup'].action = document.location.href;
            // the next step needs to be done because submit button has name="submit"
            // due to this form.submit is evaluated to an input element instead of a function which will
            // cause javascript error "submit is not a function" on calling the submit() method
            $("#SelectPublicationGroup_create").remove(); 
            document.forms['SelectPublicationGroup'].submit();
        });
    
     
  • David E. Jones

    David E. Jones - 2011-11-24

    Thanks for the extra detail Vasanth. I thought there was some reason for this,
    but looking around I can't find it. There isn't really a need for a name on a
    submit button, so I've just removed it in the trunk (in commit 12843a3). If
    anything breaks hopefully it will come up sooner than later... in basic
    testing there were no problems.

     
  • David E. Jones

    David E. Jones - 2011-11-24

    Okay, I found the reason there was a name, and that is was hard-coded. If you
    have multiple submit buttons (with different field names in the XML form) and
    you want logic to see which one was pressed you can use the input value, but
    only if they all have the same name. Basically in commit e6de970 it now always
    uses "buttonName" instead of "submit" to avoid this problem, and the tools
    screens that support multiple buttons have been updated to handle this change.

     

Log in to post a comment.