Random thoughts from ghenry

17 Jan

Generic Dojo form handlers?

written by Gavin Henry

Create one Dojo function for all your Catalyst forms

Just make sure your form has an action and method (doesn't need to be a dojoType="Form").

    function genericForm(form, resultId) {
         dojo.io.bind({
            url: form.action,
            formNode: form,
            method: form.method,
            load: function(type, data) {    
                resultId.innerHTML = data; 
            },
            error: function(type, error) { alert('Error: ' + type + "\n" + error); },
         });
        }

       <form id="browseform" name="browseform" dojoType="Form" action="[% c.uri_for('/admin/browse') %]" method="post" enctype="application/x-www-form-urlencoded">

        blah
       </form>

       <button dojoType="Button" onclick="genericForm(dojo.byId('browseform'), dojo.byId('searchres'))">Search</button></td>


       <div id="searchres"></div> 
Your captcha is:






Only the comment itself is required, but if you supply your email we'll gladly load your gravatar. We won't use your email for any other purpose or sell it to nigerian business men. Promise.
A live preview of your comment will appear in this box.