To make an easy tool that quickly converts forms to be asynchronous, and their values to a JSON object.
This really converts submitted form values to a JS object, which can then be easily converted to JSON with stringify. I cut out the actual stringification in case the data has to be checked or manipulated first.
- Add the class 'ezee-ajax-form' to a form
- Set form 'onsubmit' to the name of the function you want to handle the form with, but not with parenthesis
- (i.e.)
myFuncName
NOTmyFuncName()
- (i.e.)
- Set 'name' or 'id' on each input in the form(will check 'name' first)
- On form submit
- The page will not refresh(ajax)
- The function in form 'onsubmit' will get signature (formValuesAsObj, formElement) Then you can do whatever you want with them!
- The function name in 'onsubmit' has to point to a function on the
window
, or global scope. For instancemyHandlerObj.myHandlerFunc
won't work, at least for now. - The required class name for the form is only defined once, if you want to find/replace
- I didn't actually set up a webpack flow yet. I just ran the src through an online minifier. I know. It's true. I'm lazy. I'll get to that too eventually.
Yes. Yes it is. I wanted to make it a repo in case someone came along with a killer idea to improve it. So if you have any suggestions or improvements, feel free!